Skip to content

Commit

Permalink
Update FRAP scripts to use roi_service.getShapeStatsRestricted()
Browse files Browse the repository at this point in the history
  • Loading branch information
will-moore committed Aug 20, 2018
1 parent 805a753 commit db8fa61
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 51 deletions.
53 changes: 24 additions & 29 deletions practical/python/server/simple_frap.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# ------------------------------------------------------------------------------

"""
Simple FRAP plots from Rectangles on images.
Simple FRAP plots from Ellipses on images.
This an OMERO script that runs server-side.
"""

Expand All @@ -40,7 +40,7 @@

def run(conn, params):
"""
For each image, getTiles() for FRAP rectangle and plot mean intensity.
For each image, getTiles() for FRAP Ellipse and plot mean intensity.
Returns list of images
@param conn The BlitzGateway connection
Expand All @@ -66,32 +66,28 @@ def run(conn, params):
for image in images:
print "---- Processing image", image.id
result = roi_service.findByImage(image.getId(), None)
x = 0
y = 0
width = 0
height = 0

# Simply use any Ellipse we find...
shape_id = None
for roi in result.rois:
print "ROI: ID:", roi.getId().getValue()
for s in roi.copyShapes():
if type(s) == omero.model.RectangleI:
x = s.getX().getValue()
y = s.getY().getValue()
width = s.getWidth().getValue()
height = s.getHeight().getValue()
print "Rectangle:", x, y, width, height
if x == 0:
print " No Rectangle found for this image"
if type(s) == omero.model.EllipseI:
shape_id = s.id.val
print "Shape:", shape_id
if shape_id is None:
print " No Ellipse found for this image"
continue

c, z = 0, 0
tile = (int(x), int(y), int(width), int(height))
pixels = image.getPrimaryPixels()
# Get pixel intensities for first Channel
the_c = 0
the_z = 0
size_t = image.getSizeT()
zct_list = [(z, c, t, tile) for t in range(size_t)]
planes = pixels.getTiles(zct_list)
meanvalues = []
for i, p in enumerate(planes):
meanvalues.append(p.mean())
for t in range(size_t):
stats = roi_service.getShapeStatsRestricted([shape_id],
the_z, t, [the_c])
meanvalues.append(stats[0].mean[the_c])

print meanvalues

Expand All @@ -110,13 +106,12 @@ def run(conn, params):
plt.subplot(111)
plt.plot(meanvalues)
fig.canvas.draw()
data = np.fromstring(fig.canvas.tostring_rgb(),
dtype=np.uint8, sep='')
data = data.reshape(fig.canvas.get_width_height()[::-1] + (3,))

red = data[::, ::, 0]
green = data[::, ::, 1]
blue = data[::, ::, 2]
fig.savefig('plot.png')
pil_img = Image.open('plot.png')
np_array = np.asarray(pil_img)
red = np_array[::, ::, 0]
green = np_array[::, ::, 1]
blue = np_array[::, ::, 2]
plane_gen = iter([red, green, blue])
plot_name = image.getName() + "_FRAP_plot"
i = conn.createImageFromNumpySeq(plane_gen, plot_name, sizeC=3,
Expand All @@ -134,7 +129,7 @@ def run(conn, params):
client = scripts.client(
'Scipy_Gaussian_Filter.py',
"""
This script does simple FRAP analysis using Rectangle ROIs previously
This script does simple FRAP analysis using Ellipse ROIs previously
saved on images. If matplotlib is installed, data is plotted and new
OMERO images are created from the plots.
""",
Expand Down
40 changes: 18 additions & 22 deletions practical/python/server/simple_frap_with_figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# ------------------------------------------------------------------------------

"""
Simple FRAP plots from Rectangles on images and creates an OMERO.figure.
Simple FRAP plots from Ellipses on images and creates an OMERO.figure.
This an OMERO script that runs server-side.
"""
Expand Down Expand Up @@ -227,7 +227,7 @@ def create_omero_figure(conn, images, plots):

def run(conn, params):
"""
For each image, getTiles() for FRAP rectangle and plot mean intensity.
For each image, getTiles() for FRAP Ellipse and plot mean intensity.
Returns list of images
@param conn The BlitzGateway connection
Expand All @@ -253,32 +253,28 @@ def run(conn, params):
for image in images:
print "---- Processing image", image.id
result = roi_service.findByImage(image.getId(), None)
x = 0
y = 0
width = 0
height = 0

# Simply use any Ellipse we find...
shape_id = None
for roi in result.rois:
print "ROI: ID:", roi.getId().getValue()
for s in roi.copyShapes():
if type(s) == omero.model.RectangleI:
x = s.getX().getValue()
y = s.getY().getValue()
width = s.getWidth().getValue()
height = s.getHeight().getValue()
print "Rectangle:", x, y, width, height
if x == 0:
print " No Rectangle found for this image"
if type(s) == omero.model.EllipseI:
shape_id = s.id.val
print "Shape:", shape_id
if shape_id is None:
print " No Ellipse found for this image"
continue

c, z = 0, 0
tile = (int(x), int(y), int(width), int(height))
pixels = image.getPrimaryPixels()
# Get pixel intensities for first Channel
the_c = 0
the_z = 0
size_t = image.getSizeT()
zct_list = [(z, c, t, tile) for t in range(size_t)]
planes = pixels.getTiles(zct_list)
meanvalues = []
for i, p in enumerate(planes):
meanvalues.append(p.mean())
for t in range(size_t):
stats = roi_service.getShapeStatsRestricted([shape_id],
the_z, t, [the_c])
meanvalues.append(stats[0].mean[the_c])

print meanvalues

Expand Down Expand Up @@ -317,7 +313,7 @@ def run(conn, params):
client = scripts.client(
'Simple_FRAP.py',
"""
This script does simple FRAP analysis using Rectangle ROIs previously
This script does simple FRAP analysis using Ellipse ROIs previously
saved on images. If matplotlib is installed, data is plotted and new
OMERO images are created from the plots.
""",
Expand Down

0 comments on commit db8fa61

Please sign in to comment.