I work with 3D volumes produced by confocal microscopy. These images have x,y,z dimensions around ~1024,1024,50 and are stored in a .tif file.
I want to apply OpenCV-python cv2.adaptiveThreshold
to the whole image stack. The below code works well for a 2D image (1024,1024,1). How can I expand it for the whole volume and save the output .tif file?
img = cv2.imread("1024x1024x40.tif")
gimg = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
th = cv2.adaptiveThreshold(gimg, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 7, -20)
cv2.imshow('original',img)
cv2.imshow('Adaptive threshold',th)
cv2.waitKey(0)
cv2.destroyAllWindows()
Thanks!
Using the bioformats package:
I don't have test data but using this answer as a guide, you might try something like the following: