You are a guest. Restricted access. Read more.
Command disabled: revisions

Image manipulation

The example below shows how to load an image and apply a filter. It also show how to access its internals. Look at the complete API of the IJ package.

from ij import *
from ij.process import *
from ij.measure import *
 
file="image.png"
# we open the file manually. Generate  ImagePlus object
imp = IJ.openImage(file)
print dir(imp) # check image manipulation methods
 
# display it
imp.show()
print imp.getWidth()
 
# do manipulations with the clone
imp.getProcessor().setThreshold(174, 174, ImageProcessor.NO_LUT_UPDATE)
IJ.run(imp,"Convert to Mask","")
IJ.run(imp,"Watershed", "")
imp.show()
 
# get all the pixels
pix = imp.getProcessor().getPixels()

Next we can perform a detailed analysis of images. For example, one can create a histogram:

from ij import *
imp = IJ.openImage("http://jwork.org/scavis/data_local/img/scavis1t.png")
IJ.run(imp, "Histogram", "")
stats = imp.getStatistics()
print stats.histogram

One can extract data from image and perform manipulation. Then a new modified array can be used to build a new image. Look at the example:

Code example

  Download for this example is disabled for non-members
 1: # Images.   Subtract the minimal value to an image
 2:
 3: from ij import *
 4: from ij.process import *
 5: from ij.measure import *
 6: from ij.gui import *
 7: from java.lang import Math
 8:
 9: imp = IJ.openImage("http://jwork.org/scavis/data_local/img/scavis1.png")
10: # imp.show()
11:
12: # get pixel array
13: pix = imp.getProcessor().convertToFloat().getPixels()
14: print pix
15: # find out the minimal pixel value
16: min = reduce(Math.min, pix)
17:
18: # create a new pixel array with the minimal value subtracted
19: pix2 = map(lambda x: x - min, pix)
20:
21: img1=ImagePlus("min subtracted", FloatProcessor(imp.width, imp.height, pix2, None))
22: img1.show()

Edge detection of images

In this example, let's detect edges of the image of Scavis logo. Below we show 2 examples: one reads this logo using the URL, and the second example reads this logo from local file.

Unregistered users have a limited access to this section. One can unlock this example after becoming a full member.

The output of these scripts are below:

Note that it makes sense to convert the image into back-white. Also, one can swap the colors.

There is a very good tutorial about how to use Jython for image manipulation http://pacific.mpi-cbg.de/wiki/index.php/Jython_Scripting. To avoid plagiarism, we will stop this description here and continue with the subject of how to perform analysis of images using SCaVis API.

Navigation

Print/export