In [1]:
%run common.ipynb
from __future__ import division
In [2]:
import glob
path = "/Users/arve/Dokumenter/TFY4500/well z-scan/slide--S00/chamber--U00--V00/field--X01--Y01/"
files = glob.glob(path + "*.ome.tif")
In [3]:
# read images to a list
images = []
for f in files:
images.append(pylab.imread(f)[:,:,1]) # green channel
In [4]:
imshow(images[0])
Out[4]:
In [5]:
images[0].shape
Out[5]:
In [6]:
def maximize_image(images, stitch_size=32):
"""
Stitch images to one image based on max value to image area.
:list images: Source images
:int stitch_size: How large areas should be stitched
:return ndarray: Stitched image
"""
max_image = np.copy(images[0])
y_max, x_max = images[0].shape
Y,X = meshgrid(range(0,y_max,stitch_size), range(0,x_max,stitch_size))
points = zip(Y.flatten(), X.flatten()) # create list of tuples for less loops
for y,x in points:
# selective part of image
y_stop = y+stitch_size
x_stop = x+stitch_size
if y_stop > y_max:
y_stop = y_max
if x_stop > x_max:
x_stop = x_max
current_max = max_image[y:y_stop, x:x_stop].max()
for image in images[1:-1]: # exclude first, already copied
image_part = image[y:y_stop, x:x_stop]
image_max = image_part.max()
if image_max > current_max:
max_image[y:y_stop, x:x_stop] = np.copy(image_part)
current_max = image_max
return max_image
In [7]:
for step in range(4,32,4):
img = maximize_image(images, step)
imsave(path+str(step)+"max.tif", img)
for step in range(32,128,16):
img = maximize_image(images, step)
imsave(path+str(step)+"max.tif", img)
imsave(path+"2max.tif", maximize_image(images, 2))
In [10]:
# do the same with smoothed images
images = []
for f in files:
images.append(smooth(pylab.imread(f)[:,:,1])) # green channel
In [11]:
for step in range(4,32,4):
img = maximize_image(images, step)
imsave(path+str(step)+"smooth max.tif", img)
for step in range(32,128,16):
img = maximize_image(images, step)
imsave(path+str(step)+"smooth max.tif", img)
imsave(path+"2smooth max.tif", maximize_image(images, 2))