Commit b004479b authored by Martinez-Carvajal German's avatar Martinez-Carvajal German
Browse files

this script is not important

parent d2aa5622
""" Crop centered growing boxes from an image and save them"""
from ij import IJ
from os import path
# Saving folfer
folder = "/home/german.martinez-carvajal/Documents/Tomographie/170411COP/Segmentation(Hashemi)/BoxesofAir"
assert (path.isdir(folder)) , "Folder IS NOT A FOLDER: " + folder
# Open the image
Image_Name = "/home/german.martinez-carvajal/Documents/Tomographie/170411COP/Segmentation(Hashemi)/Air.tif"
assert (path.exists(Image_Name)) , "Image DOES NOT EXIST:" + Image_Name
print ("Reading image")
Imp = IJ.openImage(Image_Name)
print('Image is: ', Imp)
Imp.show()
# Stoping criterium #1
Counter = 0
Max_Boxes = 5
# Dimensions
Height = Imp.height
Width = Imp.width
# This piece of code is a for loop that:
# Cropes a squared ROI
# Saves it as TIFF
# The ROI's size increases every step
from ij import ImagePlus
from ij.io import FileSaver
Size = 50 # Width of the squared ROI
Ip = Imp.getImageStack()
Rois = []
while True:
X_corner = (Width-Size)/2
Y_corner = (Height-Size)/2
print ('Corner and size', X_corner, Y_corner, Size)
Ip_New = Ip.crop ( X_corner, Y_corner, 0, Size, Size, Imp.getNSlices())
Imp_New = ImagePlus("Duplicate", Ip_New) # duplicate = duplicate whole stack
#Imp_New.show()
print(Imp_New)
fs = FileSaver(Imp_New)
filepath = folder + "/" + "Box" + str(Size) + ".tif"
fs.saveAsTiff(filepath)
Size += 50 # Widht of the squared ROI
Counter += 1
if Size >= Imp.width: # Stopping criterium #2
break
if Counter >= Max_Boxes:
break
print('OK Finished')
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment