This commit is contained in:
2018-04-17 12:05:48 +02:00
parent 14edc0e745
commit 58a1260003
428 changed files with 41350 additions and 477 deletions

38
script/image/ImageStats.py Executable file
View File

@@ -0,0 +1,38 @@
from ijutils import *
from mathutils import fit_gaussian
from ch.psi.pshell.imaging.Overlays import *
import ch.psi.pshell.imaging.Pen as Pen
image = img
image = tst
def wait_next():
camera.waitNext(250)
def get_centroid():
bi = image.getImage()
op = show_panel(bi, "Original")
if bi is None:
return None
ip = load_image(bi)
grayscale(ip)
invert(ip)
gaussian_blur(ip)
auto_threshold(ip)
#binary_erode(ip)
show_panel(ip.getBufferedImage(), "Image")
(results,output_img)=analyse_particles(ip, 1000,20000, print_table=True)
op.clearOverlays()
show_panel(output_img.getBufferedImage(), "Outlines")
if results.size()>0:
print results
centroid = (results.getValue("XM",0), results.getValue("YM",0))
ov = Crosshairs(Pen(java.awt.Color.ORANGE), java.awt.Point(int(centroid[0]),int(centroid[1])), java.awt.Dimension(15,15))
op.addOverlay(ov)
return centroid
get_centroid()

42
script/image/image.py Executable file
View File

@@ -0,0 +1,42 @@
###################################################################################################
# Demonstrate creation of an image filters and new source based on filter.
# Also demonstrate creation of image histogram and use of overlays.
###################################################################################################
import ch.psi.pshell.imaging.Filter as Filter
from ch.psi.pshell.imaging.Utils import *
from ch.psi.pshell.imaging.Overlays import *
import ch.psi.pshell.imaging.Pen as Pen
last = None
class MyFilter(Filter):
def process(self, image, data):
global last
image = grayscale(image)
i=None
if last is not None:
i = sub(image,last, False)
i = rescale(i,100.0, 0, True)
i = add(i, last, True)
i = rescale(i,10.0, 0, True)
last = image
return i
def translate2(image, minV, maxV,inPlace):
range = float(maxV - minV)
scale = (255.0 / range) if (range > 0) else 1.0
offset = -minV
return rescale(image, scale,offset, inPlace)
class MyFilter2(Filter):
def process(self, image, data):
image = grayscale(image)
image = translate(image, 100, 200, True)
#image = rescale(image, 1.0, 200.0, False)
return image
#Setting the filter to a source
img.setFilter(MyFilter2())

148
script/image/image10.py Executable file
View File

@@ -0,0 +1,148 @@
###################################################################################################
# Example of using ImageJ functionalities through ijutils.
###################################################################################################
from ijutils import *
import java.awt.Color as Color
#Image Loading
ip = load_image("images/img2.png", title="Image2")
#Basic image manipulation: creation, copying, padding, saving
resized = resize(ip, 300,300)
save_image(resized,get_context().setup.expandPath("{images}/resized.tiff") ,"tiff")
crop=sub_image(ip,10,20,50,30)
bin_im = binning(ip,2)
new_im = new_image(256, 256, "color")
copy_image_to(bin_im, new_im, 20, 20)
pad_im = pad_image(ip, 1, 2, 3, 4, Color.RED)
stack=create_stack([ip,resized,crop, bin_im, new_im, pad_im], title = "Basic Functions")
save_image(stack,get_context().setup.expandPath("{images}/stack.tiff") ,"tiff")
stack.show()
#Decomposing color channels
create_stack([ get_channel(ip, "red"),
get_channel(ip, "green"),
get_channel(ip, "blue"),
get_channel(ip, "alpha"),
grayscale(get_channel(ip, "brightness"), False)], title = "Color Decomposition").show()
#Basic functions (in_place)
aux1 = ip.duplicate()
aux1.show()
grayscale(aux1)
gaussian_blur(aux1); aux1.repaintWindow()
invert(aux1); aux1.repaintWindow()
smooth(aux1); aux1.repaintWindow()
sharpen(aux1); aux1.repaintWindow()
noise(aux1, 100); aux1.repaintWindow()
#Changing LUT
aux = ip.duplicate()
aux = grayscale(aux, in_place=False)
r,g,b = [],[],[]
for i in range(256):
r.append(0)
g.append(0)
b.append(i)
set_lut(aux, r, g, b)
aux.show()
#Histogram
plot(get_histogram(ip))
#Binarization and binary operations
aux = grayscale(ip, in_place = False)
bin = ip.duplicate()
ip_bin = auto_threshold(aux, in_place=False)
create_stack([ ip_bin,
binary_outline(ip_bin, in_place=False),
binary_dilate(ip_bin, in_place=False),
binary_erode(ip_bin, in_place=False),
binary_open(ip_bin, in_place=False),
binary_close(ip_bin, in_place=False),
binary_skeletonize(ip_bin, in_place=False),
binary_fill_holes(ip_bin, in_place=False),
binary_outline(ip_bin, in_place=False)], title = "Binarization").show()
#EDM, const & image operations
aux = grayscale(ip, in_place = False)
ip_bin = auto_threshold(aux, in_place=False)
binary_fill_holes(ip_bin)
edm = edm(ip_bin, in_place=False)
ws = watershed(ip_bin, in_place=False)
up = ultimate_points(ip_bin, in_place=False)
vr = veronoi(ip_bin, in_place=False)
edm_disp = remap(edm, in_place=False)
ws_disp = grayscale(ws, False)
up_disp = enhance_contrast(up, in_place=False)
vr_disp = enhance_contrast(vr, in_place=False)
create_stack([edm_disp, aux, ip_bin, ws_disp, up_disp, vr_disp], title = "EDM Operations").show()
final = grayscale(ip_bin, in_place = False)
op_const(final,"add", -200)
op_image(final, vr_disp, 'or')
op_image(final, up_disp, 'or')
final.show()
aux = grayscale(ip, in_place = False)
create_stack([ aux,
subtract_background(aux, in_place=False),
smooth(aux, False),
sharpen(aux, False),
edges(aux, False),
bandpass_filter(aux,0, 5, in_place=False),
bandpass_filter(aux,5, 100, in_place=False),
op_const(aux,"and", 127, False),
convolve(aux, KERNEL_BLUR, False),
convolve(aux, KERNEL_SHARPEN, False),
convolve(aux, KERNEL_SHARPEN_2, False),
convolve(aux, KERNEL_LIGHT, False),
convolve(aux, KERNEL_DARK, False),
convolve(aux, KERNEL_EDGE_DETECT, False),
convolve(aux, KERNEL_EDGE_DETECT_2, False),
convolve(aux, KERNEL_DIFFERENTIAL_EDGE_DETECT, False),
convolve(aux, KERNEL_PREWITT, False),
convolve(aux, KERNEL_SOBEL, False)
], title = "General Operations").show()
#Rank operators
rank_opers = []
for op in "mean", "min", "max", "variance", "median", "close_maxima", "open_maxima", "remove_outliers", "remove_nan", "despeckle":
rank_opers.append(op_rank(aux,op, in_place=False, kernel_radius=1))
create_stack(rank_opers, title = "Rank Operations").show()
#Reslicing
#orig = load_image("{data}/img/img2.png")
orig = resize(ip, 300,200)
grayscale(orig)
images=[]
for i in range (20):
images.append(orig.duplicate())
op_const(orig, "multiply", 0.9)
stack=create_stack(images, title = "Original Stack")
#stack.show()
r1 = reslice(stack, start_at="Left", title="Reslice Horizontally")
r2 = reslice(stack, start_at="Top", title="Reslice Vertically")
r1.show()
r2.show()
#Particle Analysis
aux = grayscale(ip, in_place = False)
auto_threshold(aux)
#binary_fill_holes(aux)
#aux.show()
(results,output_img)=analyse_particles(aux, 100,1000, print_table=True)
output_img.show()

22
script/image/image11.py Executable file
View File

@@ -0,0 +1,22 @@
run("pip")
orig = load_image("{data}/img/img2.png")
#orig.show()
#Resize
resized = resize(orig, 300,300)
#Sub-image
crop=sub_image(orig,10,20,50,30)
bin_im = bin_image(orig,2)
new_im = new_image(256, 256, "color")
pad_im = pad_image(orig, 1, 2, 3, 4, Color.RED)
stack=create_stack([orig,resized,crop, bin_im, new_im, pad_im])
save_image(stack,context.setup.expandPath("{data}/img/out.tiff") ,"tiff")
stack.show()

25
script/image/image12.py Executable file
View File

@@ -0,0 +1,25 @@
run("pip")
orig = load_image("{data}/img/img2.png")
orig = resize(orig, 300,200)
grayscale(orig)
images=[]
for i in range (20):
images.append(orig.duplicate())
op_const(orig, "multiply", 0.9)
stack=create_stack(images)
stack.show()
r1 = reslice(stack, start_at="Left")
r2 = reslice(stack, start_at="Top")
r1.show()
r2.show()
#x=new_image(800, 600, image_type="byte")
#copy_image_to(orig, x, 100, 200)
#x.show()

28
script/image/image13.py Executable file
View File

@@ -0,0 +1,28 @@
#run("pip")
from pip import *
ip = load_image("{data}/img/img3.png")
auto_threshold(ip)
#binary_outline(ip)
#binary_fill_holes(ip)
ip.show()
(results,output_img)=analyse_particles(ip, 100,1000, print_table=True)
output_img.show()
"""
"""
#static int SHOW_MASKS
#static int SHOW_NONE
#static int SHOW_OUTLINES
#static int SHOW_OVERLAY_MASKS
#static int SHOW_OVERLAY_OUTLINES
#static int SHOW_PROGRESS
#static int SHOW_RESULTS
#static int SHOW_ROI_MASKS

164
script/image/image14.py Executable file
View File

@@ -0,0 +1,164 @@
###################################################################################################
# Example of using ImageJ functionalities through ijutils.
###################################################################################################
from ijutils import *
import java.awt.Color as Color
#Image Loading
ip1 = load_image("images/img1.png", title="Image1")
ip2 = load_image("images/img2.png", title="Image2")
ip3 = load_image("images/img3.png", title="Grid")
ip4 = load_image("images/img4.png", title="Square")
#Basic operaions creation, copying, padding, saving
resized = resize(ip2, 300,300)
save_image(resized,get_context().setup.expandPath("~/resized.tiff") ,"tiff")
crop=sub_image(ip2,10,20,50,30)
bin_im = binning(ip2,2)
new_im = new_image(256, 256, "color")
copy_image_to(bin_im, new_im, 20, 20)
pad_im = pad_image(ip2, 1, 2, 3, 4, Color.RED)
stack=create_stack([ip2,resized,crop, bin_im, new_im, pad_im], title = "Basic Functions")
save_image(stack,get_context().setup.expandPath("~/stack.tiff") ,"tiff")
stack.show()
#Decomposing color channels
ip1.show()
create_stack([ get_channel(ip1, "red"),
get_channel(ip1, "green"),
get_channel(ip1, "blue"),
get_channel(ip1, "alpha"),
grayscale(get_channel(ip1, "brightness"), False)], title = "Color Decomposition").show()
#Histogram
plot(get_histogram(ip1))
#Changing LUT
ip = ip1.duplicate()
ip = grayscale(ip, in_place=False)
r,g,b = [],[],[]
for i in range(256):
r.append(0)
g.append(0)
b.append(i)
set_lut(ip, r, g, b)
ip.show()
#Basic functions (in_place)
ip = ip1.duplicate()
ip.show()
grayscale(ip)
gaussian_blur(ip)
invert(ip)
smooth(ip)
sharpen(ip)
#edge(ip)
#add(ip)
#noise(ip, 100)
ip.show()
#Binarization and binary operations
ip = grayscale(ip2, in_place = False)
bin = ip1.duplicate()
ip_bin = auto_threshold(ip, in_place=False)
create_stack([ ip_bin,
binary_outline(ip_bin, in_place=False),
binary_dilate(ip_bin, in_place=False),
binary_erode(ip_bin, in_place=False),
binary_open(ip_bin, in_place=False),
binary_close(ip_bin, in_place=False),
binary_skeletonize(ip_bin, in_place=False),
binary_fill_holes(ip_bin, in_place=False),
binary_outline(ip_bin, in_place=False)], title = "Binarization").show()
#EDM, const & image operations
ip = grayscale(ip2, in_place = False)
ip_bin = auto_threshold(ip, in_place=False)
binary_fill_holes(ip_bin)
edm = edm(ip_bin, in_place=False)
ws = watershed(ip_bin, in_place=False)
up = ultimate_points(ip_bin, in_place=False)
vr = veronoi(ip_bin, in_place=False)
edm_disp = remap(edm, in_place=False)
ws_disp = grayscale(ws, False)
up_disp = enhance_contrast(up, in_place=False)
vr_disp = enhance_contrast(vr, in_place=False)
create_stack([edm_disp, ip, ip_bin, ws_disp, up_disp, vr_disp], title = "EDM Operations").show()
final = grayscale(ip_bin, in_place = False)
op_const(final,"add", -200)
op_image(final, vr_disp, 'or')
op_image(final, up_disp, 'or')
final.show()
#Correlate, convolve, deconvolve
grayscale(ip3)
grayscale(ip4)
cor = op_fft(ip3, ip4, "correlate", True)
con = op_fft(ip3, ip4, "convolve", True)
dec = op_fft(con, ip4, "deconvolve", True)
create_stack([ip3,ip4, grayscale(cor,False),grayscale(con,False),grayscale(dec,False)], title = "Correlation").show()
ip = grayscale(ip2, in_place = False)
create_stack([ ip,
subtract_background(ip, in_place=False),
smooth(ip, False),
sharpen(ip, False),
edges(ip, False),
bandpass_filter(ip,0, 5, in_place=False),
bandpass_filter(ip,5, 100, in_place=False),
op_const(ip,"and", 127, False),
convolve(ip, KERNEL_BLUR, False),
convolve(ip, KERNEL_SHARPEN, False),
convolve(ip, KERNEL_SHARPEN_2, False),
convolve(ip, KERNEL_LIGHT, False),
convolve(ip, KERNEL_DARK, False),
convolve(ip, KERNEL_EDGE_DETECT, False),
convolve(ip, KERNEL_EDGE_DETECT_2, False),
convolve(ip, KERNEL_DIFFERENTIAL_EDGE_DETECT, False),
convolve(ip, KERNEL_PREWITT, False),
convolve(ip, KERNEL_SOBEL, False)
], title = "General Operations").show()
#Rank operators
rank_opers = []
for op in "mean", "min", "max", "variance", "median", "close_maxima", "open_maxima", "remove_outliers", "remove_nan", "despeckle":
rank_opers.append(op_rank(ip,op, in_place=False, kernel_radius=1))
create_stack(rank_opers, title = "Rank Operations").show()
#Reslicing
#orig = load_image("{data}/img/img2.png")
orig = resize(ip2, 300,200)
grayscale(orig)
images=[]
for i in range (20):
images.append(orig.duplicate())
op_const(orig, "multiply", 0.9)
stack=create_stack(images, title = "Original Stack")
#stack.show()
r1 = reslice(stack, start_at="Left", title="Reslice Horizontally")
r2 = reslice(stack, start_at="Top", title="Reslice Vertically")
r1.show()
r2.show()
#Particle Analysis
ip = grayscale(ip2, in_place = False)
auto_threshold(ip)
#binary_fill_holes(ip)
#ip.show()
(results,output_img)=analyse_particles(ip, 100,1000, print_table=True)
output_img.show()

30
script/image/image2.py Executable file
View File

@@ -0,0 +1,30 @@
###################################################################################################
# Demonstrate creation of an image filters and new source based on filter.
# Also demonstrate creation of image histogram and use of overlays.
###################################################################################################
import ch.psi.pshell.imaging.Filter as Filter
from ch.psi.pshell.imaging.Utils import *
from ch.psi.pshell.imaging.Overlays import *
import ch.psi.pshell.imaging.Pen as Pen
import net.imglib2.script.bufferedimage.BufferedImageImg as BufferedImageImg
class MyFilter(Filter):
def process(self, image, data):
im = BufferedImageImg(image)
global last
image = grayscale(image)
i=None
if last is not None:
i = sub(image,last, False)
i = rescale(i,100.0, 0, True)
i = add(i, last, True)
i = rescale(i,10.0, 0, True)
last = image
return i
#Setting the filter to a source
img.setFilter(MyFilter())

27
script/image/image3.py Executable file
View File

@@ -0,0 +1,27 @@
import ch.psi.pshell.imaging.Filter as Filter
from ch.psi.pshell.imaging.Utils import *
from ch.psi.pshell.imaging.Overlays import *
import ch.psi.pshell.imaging.Pen as Pen
import net.imglib2.script.bufferedimage.BufferedImageImg as BufferedImageImg
import net.imglib2.script.algorithm.FFT as FFT
import net.imglib2.img.display.imagej.ImageJFunctions as ImageJFunctions
bi = None
fftimg = None
class MyFilter(Filter):
def process(self, image, data):
#image = rescale(image, 1.0, -20, True)
image = grayscale(image)
global bi, fftimg
bi = image
im = BufferedImageImg(image)
fft = FFT(im)
fftimg = fft
ret = ImageJFunctions.wrap(fft.image(), "").getBufferedImage()
return ret
#Setting the filter to a source
tst.setFilter(MyFilter())
tst.initialize()

28
script/image/image4.py Executable file
View File

@@ -0,0 +1,28 @@
run("pip")
img = BufferedImageImg(bi)
diamondShape = DiamondShape( 8 );
ImageJFunctions.show( img, "Source" )
#ImageJFunctions.show( Erosion.erode( img, StructuringElements.diamond( 8, 2, True ), 1 ), "NewSourceDecomp" )
#ImageJFunctions.show( Erosion.erode( img, StructuringElements.diamond( 8, 2, False ), 1 ), "NewSourceStraight" )
#ImageJFunctions.show( Erosion.erode( img, diamondShape, 1 ), "NewSourceSingle" )
#Full
#ImageJFunctions.show( Erosion.erodeFull( img, StructuringElements.diamond( 8, 2, True ), 1 ), "NewFullSourceDecomp" )
#ImageJFunctions.show( Erosion.erodeFull( img, StructuringElements.diamond( 8, 2, False ), 1 ), "NewFullSourceStraight" )
#ImageJFunctions.show( Erosion.erodeFull( img, diamondShape, 1 ), "NewFullSourceSingle" )
strel = StructuringElements.disk( 6, 2, 4 )
for shape in strel:
print shape
print MorphologyUtils.printNeighborhood( shape, 2 )
minVal = FloatType(0)
ImageJFunctions.show (Dilation.dilateFull( img, strel, minVal, 1 ))

24
script/image/image5.py Executable file
View File

@@ -0,0 +1,24 @@
import ch.psi.pshell.imaging.Filter as Filter
from ch.psi.pshell.imaging.Utils import *
from ch.psi.pshell.imaging.Overlays import *
import ch.psi.pshell.imaging.Pen as Pen
run("pip")
renderer = show_panel(tst)
com_overlay = Crosshairs(Pen(java.awt.Color.WHITE), java.awt.Point(-1,-1), java.awt.Dimension(15,15))
renderer.clearOverlays()
renderer.addOverlays([com_overlay,])
class MyFilter(Filter):
def process(self, image, data):
aux = rescale(image, 1.0, -20, False)
ip = ImagePlus("Img", aux)
stats = get_statistics(ip,Measurements.CENTER_OF_MASS | Measurements.CENTROID )
(x,y) = (stats.xCenterOfMass, stats.yCenterOfMass)
print x,y
com_overlay.update(java.awt.Point(int(x),int(y)))
return image
tst.setFilter(MyFilter())
tst.refresh()

108
script/image/image6.py Executable file
View File

@@ -0,0 +1,108 @@
run("pip")
ip1_orig = load_image("{data}/img/img1.png")
ip1 = ip1_orig.duplicate()
#Decomposing color channels
ip1.show()
create_stack([get_channel(ip1, "red"), get_channel(ip1, "green"), get_channel(ip1, "blue"), get_channel(ip1, "alpha"), grayscale(get_channel(ip1, "brightness"), False)]).show()
ip2 = ip1_orig.duplicate()
grayscale(ip2)
r,g,b = [],[],[]
for i in range(256):
r.append(0)
g.append(0)
b.append(i)
set_lut(ip2, r, g, b)
ip2.show()
"""
#gaussian_blur(ip1)
#invert(ip1)
#smooth(ip1)
#sharpen(ip1)
#edge(ip1)
#add(ip1)
#noise(ip1, 100)
plot(get_histogram(ip1))
#plot(get_array(ip1))
#plot(get_line(ip1, 0,0, 100,100))
#plot(get_pixels(ip1))
#plot (get_col(ip1,1))
print get_pixel_range(ip1)
print get_num_channels(ip1)
print get_pixel(ip1,0,0)
print get_pixel_array(ip1,0,0)
stats = get_statistics(ip1)
print stats
s2 = get_statistics(ip1,Measurements.CENTER_OF_MASS | Measurements.CENTROID )
print s2
print s2.xCenterOfMass, s2.yCenterOfMass
print s2.xCentroid , s2.yCentroid
#pr1.subtract(80)
#pr1.setMinAndMax(20,80)
#pr1.rotate(20)
"""
ip1_orig = load_image("{data}/img/img1.png")
ip1_grayscale = ip1_orig.duplicate()
grayscale(ip1_grayscale)
pr1 = ip1_grayscale.getProcessor()
#ip1 = threshold(ip1, 150, 255)
#auto_threshold(ip1)
#pr1.dilate()
#pr1.erode()
"""
#print pr1.getAutoThreshold()
pr1.resetBinaryThreshold()
pr1.setAutoThreshold(ImageProcessor.ISODATA2, ImageProcessor.NO_LUT_UPDATE)
#pr1.setAutoThreshold(AutoThresholder.getMethods()[0], True , ImageProcessor.NO_LUT_UPDATE);
minThreshold = pr1.getMinThreshold();
maxThreshold = pr1.getMaxThreshold();
pr1.resetThreshold()
#pr1.threshold(80)
fcolor=255
bcolor=0
lut = []
for i in range(256):
if minThreshold <= i <=maxThreshold:
lut.append(fcolor)
else:
lut.append(bcolor)
pr1.applyTable(lut);
#pr1.autoThreshold()
#pr1.setBinaryThreshold()
min_threshold, max_threshold = 50, 200
pr1.setThreshold(min_threshold, max_threshold, ImageProcessor.NO_LUT_UPDATE);
WindowManager.setTempCurrentImage(ip1);
thresholder=Thresholder();
thresholder.run("mask");
bp = WindowManager.getCurrentImage().getProcessor();
ip1 = ImagePlus(ip1.getTitle() + " binary", bp);
"""
#shadows(ip1_grayscale, "north")
#voronoi(ip1_grayscale)
#ip1_grayscale.show()

45
script/image/image7.py Executable file
View File

@@ -0,0 +1,45 @@
run("pip")
ip1_orig = load_image("{data}/img/img2.png")
grayscale(ip1_orig)
bin = ip1_orig.duplicate()
auto_threshold(bin)
edm = edm(bin, in_place=False)
ws = bin.duplicate()
ws.setTitle("watershed")
watershed(ws)
up = bin.duplicate()
up.setTitle("ultimate points")
ultimate_points(up)
vr = bin.duplicate()
vr.setTitle("veronoi")
veronoi(vr)
edm_disp = remap(edm, in_place=False)
#edm.duplicate()
#edm_disp.getProcessor().setMinAndMax(0,get_statistics(edm,Measurements.MIN_MAX).max)
ws_disp = grayscale(ws, False)
up_disp = enhance_contrast(up, in_place=False)
vr_disp = enhance_contrast(vr, in_place=False)
create_stack([edm_disp, ip1_orig, bin, edm_disp, ws_disp, up_disp, vr_disp]).show()
final = bin.duplicate()
grayscale(final)
op_const(final,"add", -200)
op_image(final, vr_disp, 'or')
op_image(final, up_disp, 'or')
final.show()

47
script/image/image8.py Executable file
View File

@@ -0,0 +1,47 @@
run("pip")
ip1_orig = load_image("{data}/img/img1.png")
ip1_grayscale = ip1_orig.duplicate()
grayscale(ip1_grayscale)
pr1 = ip1_grayscale.getProcessor()
#ip1_grayscale.show()
ip1_max = find_maxima(ip1_grayscale, 50, output_type=MaximumFinder.SINGLE_POINTS)
#ip1_max.show()
(x,y) = get_maxima_points(ip1_grayscale,50)
p=plot(x, xdata=Convert.toDouble(y))[0]
p.getSeries(0).setPointSize(5)
p.getSeries(0).setLinesVisible(False)
"""
f = image_fft(ip1_grayscale, False)
#f.getProcessor().fillOval(50,50, 50, 50)
#f.getProcessor().fillOval(250,250, 50, 50)
i = image_ffti(f, False)
#f.show()
#i.show()
"""
#bandpass_filter(ip1_grayscale,0, 5)
#ip1_grayscale.show()
#edges(ip1_grayscale)
#bandpass_filter(ip1,20,40)
#ip1.show()
ip_bin = ip1_grayscale.duplicate()
threshold(ip_bin, 80, 255)
#binary_skeletonize(ip_bin)
#enhance_contrast(ip1_grayscale)
op_rank (ip1_grayscale, "max", kernel_radius = 1.0)
ip1_grayscale.show()
ip_bin.show()

15
script/image/image9.py Executable file
View File

@@ -0,0 +1,15 @@
run("pip")
ip1 = load_image("{data}/img/grid.png", title="Grid")
ip2 = load_image("{data}/img/square.png", title="Square")
grayscale(ip1)
grayscale(ip2)
cor = op_fft(ip1, ip2, "correlate", True)
con = op_fft(ip1, ip2, "convolve", True)
dec = op_fft(con, ip2, "deconvolve", True)
create_stack([ip1,ip2,grayscale(cor,False),grayscale(con,False),grayscale(dec,False)]).show()

164
script/image/imagej.py Executable file
View File

@@ -0,0 +1,164 @@
###################################################################################################
# Example of using ImageJ functionalities through ijutils.
###################################################################################################
from ijutils import *
import java.awt.Color as Color
#Image Loading
ip1 = load_image("{images}/img1.png", title="Image1")
ip2 = load_image("{images}/img2.png", title="Image2")
ip3 = load_image("{images}/img3.png", title="Grid")
ip4 = load_image("{images}/img4.png", title="Square")
#Basic operaions creation, copying, padding, saving
resized = resize(ip2, 300,300)
save_image(resized,context.setup.expandPath("~/resized.tiff") ,"tiff")
crop=sub_image(ip2,10,20,50,30)
bin_im = binning(ip2,2)
new_im = new_image(256, 256, "color")
copy_image_to(bin_im, new_im, 20, 20)
pad_im = pad_image(ip2, 1, 2, 3, 4, Color.RED)
stack=create_stack([ip2,resized,crop, bin_im, new_im, pad_im], title = "Basic Functions")
save_image(stack,context.setup.expandPath("~/stack.tiff") ,"tiff")
stack.show()
#Decomposing color channels
ip1.show()
create_stack([ get_channel(ip1, "red"),
get_channel(ip1, "green"),
get_channel(ip1, "blue"),
get_channel(ip1, "alpha"),
grayscale(get_channel(ip1, "brightness"), False)], title = "Color Decomposition").show()
#Histogram
plot(get_histogram(ip1))
#Changing LUT
ip = ip1.duplicate()
ip = grayscale(ip, in_place=False)
r,g,b = [],[],[]
for i in range(256):
r.append(0)
g.append(0)
b.append(i)
set_lut(ip, r, g, b)
ip.show()
#Basic functions (in_place)
ip = ip1.duplicate()
ip.show()
grayscale(ip)
gaussian_blur(ip)
invert(ip)
smooth(ip)
sharpen(ip)
#edge(ip)
#add(ip)
#noise(ip, 100)
ip.show()
#Binarization and binary operations
ip = grayscale(ip2, in_place = False)
bin = ip1.duplicate()
ip_bin = auto_threshold(ip, in_place=False)
create_stack([ ip_bin,
binary_outline(ip_bin, in_place=False),
binary_dilate(ip_bin, in_place=False),
binary_erode(ip_bin, in_place=False),
binary_open(ip_bin, in_place=False),
binary_close(ip_bin, in_place=False),
binary_skeletonize(ip_bin, in_place=False),
binary_fill_holes(ip_bin, in_place=False),
binary_outline(ip_bin, in_place=False)], title = "Binarization").show()
#EDM, const & image operations
ip = grayscale(ip2, in_place = False)
ip_bin = auto_threshold(ip, in_place=False)
binary_fill_holes(ip_bin)
edm = edm(ip_bin, in_place=False)
ws = watershed(ip_bin, in_place=False)
up = ultimate_points(ip_bin, in_place=False)
vr = veronoi(ip_bin, in_place=False)
edm_disp = remap(edm, in_place=False)
ws_disp = grayscale(ws, False)
up_disp = enhance_contrast(up, in_place=False)
vr_disp = enhance_contrast(vr, in_place=False)
create_stack([edm_disp, ip, ip_bin, ws_disp, up_disp, vr_disp], title = "EDM Operations").show()
final = grayscale(ip_bin, in_place = False)
op_const(final,"add", -200)
op_image(final, vr_disp, 'or')
op_image(final, up_disp, 'or')
final.show()
#Correlate, convolve, deconvolve
grayscale(ip3)
grayscale(ip4)
cor = op_fft(ip3, ip4, "correlate", True)
con = op_fft(ip3, ip4, "convolve", True)
dec = op_fft(con, ip4, "deconvolve", True)
create_stack([ip3,ip4, grayscale(cor,False),grayscale(con,False),grayscale(dec,False)], title = "Correlation").show()
ip = grayscale(ip2, in_place = False)
create_stack([ ip,
subtract_background(ip, in_place=False),
smooth(ip, False),
sharpen(ip, False),
edges(ip, False),
bandpass_filter(ip,0, 5, in_place=False),
bandpass_filter(ip,5, 100, in_place=False),
op_const(ip,"and", 127, False),
convolve(ip, KERNEL_BLUR, False),
convolve(ip, KERNEL_SHARPEN, False),
convolve(ip, KERNEL_SHARPEN_2, False),
convolve(ip, KERNEL_LIGHT, False),
convolve(ip, KERNEL_DARK, False),
convolve(ip, KERNEL_EDGE_DETECT, False),
convolve(ip, KERNEL_EDGE_DETECT_2, False),
convolve(ip, KERNEL_DIFFERENTIAL_EDGE_DETECT, False),
convolve(ip, KERNEL_PREWITT, False),
convolve(ip, KERNEL_SOBEL, False)
], title = "General Operations").show()
#Rank operators
rank_opers = []
for op in "mean", "min", "max", "variance", "median", "close_maxima", "open_maxima", "remove_outliers", "remove_nan", "despeckle":
rank_opers.append(op_rank(ip,op, in_place=False, kernel_radius=1))
create_stack(rank_opers, title = "Rank Operations").show()
#Reslicing
#orig = load_image("{data}/img/img2.png")
orig = resize(ip2, 300,200)
grayscale(orig)
images=[]
for i in range (20):
images.append(orig.duplicate())
op_const(orig, "multiply", 0.9)
stack=create_stack(images, title = "Original Stack")
#stack.show()
r1 = reslice(stack, start_at="Left", title="Reslice Horizontally")
r2 = reslice(stack, start_at="Top", title="Reslice Vertically")
r1.show()
r2.show()
#Particle Analysis
ip = grayscale(ip2, in_place = False)
auto_threshold(ip)
#binary_fill_holes(ip)
#ip.show()
(results,output_img)=analyse_particles(ip, 100,1000, print_table=True)
output_img.show()