I’d like to convert my previous workflow using raw .CZI files to one based on our OMERO server. One area that I don’t quite understand is how ROIs work in omero-py.
To give some background on the problem, I’m performing cell segmentation with Cytoflow. I’d like to generate representative cells by normalizing and averaging all segmented cells in an image or group of images. What I did before OMERO was to use Sci-kit image to loop through the masked image, align the cells horizontally (they are rod shaped bacteria), and save the intensity of each cell to a dataframe. Something like as follows:
image = czifile.imread(f)
gfp = image[gfp_channel,:,:,0]
labelled_image = skimage.measure.label(mask)
feature_table = skimage.measure.regionprops(labelled_image)
Averaged_GFP_2D = np.zeros([200, 500]) #create empty array to fill with pixel data
CellSize_sort = []
CellSize_label = []
# throw away poorly segmented cells
for i in feature_table:
if (i.area) > 40 and (i.major_axis_length/i.minor_axis_length) > 2:
CellSize_sort.append(i.major_axis_length)
CellSize_label.append(i.label)
n=0
for i in np.argsort(CellSize_sort):
sample = feature_table[CellSize_label[i]-1]
angle = np.degrees(sample.orientation)
length = sample.major_axis_length
width = sample.minor_axis_length
# get pixel data from masked channel of interest
target_channel = gfp[sample.slice[0].start:sample.slice[0].stop, sample.slice[1].start:sample.slice[1].stop]
target_channel = target_channel * sample.filled_image
# rotate masked pixel data to be horizontal
rotated_image = sk.transform.rotate(target_channel, -angle-90, resize = True)
masked = target_channel[target_channel > 0]
H, W = rotated_image.shape
image_center = rotated_image[max([int(H/2-width/2), 0]):int(H/2+width/2)+1,max([0,int(W/2-length/2)]):int(W/2+length/2)]
# collect pixel data in a dataframe for later averaging/processing.
Averaged_GFP_2D = Averaged_GFP_2D + sk.transform.resize(image_center, (Averaged_GFP_2D.shape[0],Averaged_GFP_2D.shape[1]))
n+=1
With OMERO, the images are loaded from the OMERO server, segmented, and the resulting mask is then saved back to the image as an ROI. An example notebook of my segmentation workflow with OMERO is here. Is it possible to get the ROIs to work with skimage.measure.regionprops
, as I did before, or is there perhaps a better way? I followed the OMERO Python developer documentation and was able to load the ROIs, I just cant figure out the best way to get their pixel intensities out as arrays that can be processed. I have a notebook with my work in progress here.
Apologies for the long-winded question.
Jonathan