Wednesday, May 4, 2011

Programming

Finished reading the tutorial documentation for python. Finally found a 64bit version of JIL for python 2.6.

Ran through some of the documentation for that, and got a little ways.

It appears Python is very useful for images, quick short commands to change what you need. I don't know how well anything else will work in python when it comes to trying to measure the images' segmented objects; if it can even segment the objects.

Original Image



Image converted to grayscale, and then converted to binary with a threshold of 128.

im = Image.open("image.tif").convert("L").point(lambda i: i >= 128 and 255 or 0)

Another way of converting to binary/gray scale. Image didn't go all white and black.

im = Image.open("image.tif").convert("1").point(lambda i: i >= 128 and 255 or 0)
Image remained RGB, did the threshold of 128.
im = Image.open("image.tif").point(lambda i: i >= 128 and 255 or 0)


I tried working with JMF, and "Marvin's Framework"

http://marvinproject.sourceforge.net/en/index.html

There is a lot of documentation; it could be useful, will look at getting this set up to use and test.

Built a plugin usable for ImageJ; The plugin doesn't do much other than converting the image to grayscale, finding the edges, and converting that to binary with a threshold of 128.



Java built ImageJ Plugin function ran. See code.


Seems like it's an easy to use utility, documentation is well written for ImageJ.

        IJ ij = new IJ();
        Image i = ij.getImage().getImage();
       
        BufferedImage buffImage = new BufferedImage(i.getWidth(null),i.getHeight(null),BufferedImage.TYPE_BYTE_GRAY);
        Graphics g = buffImage.getGraphics();
        g.drawImage(i,0,0,null);
        g.dispose();
        Image im = buffImage;
        ij.getImage().setImage(im);
       
        ImageProcessor IP = ij.getImage().getProcessor();
        IP.findEdges();
        ByteProcessor BP = (ByteProcessor) IP.convertToByte(false);
        BP.threshold(128);
        ij.getImage().repaintWindow();

2 comments:

  1. Good.
    The gradient in the aqua image above is a result of uneven lighting by the microscope and what I was trying to describe on Monday.

    ReplyDelete
  2. This is where a little bit of user interaction would really help. See if you can add a human into your ip "loop" by asking them to select a square area to sample the bg colour (using an interactive marquee). Using this small area, you can calculate some statistics on the sample pixels (the mean, median, max, min, sd, etc. ) to pick the best theshold. This is like a really, really simple background classifier.

    You can try it in RGB or grayscale. Converting to another colourspace like HSL/HSB or YCbCr may alos help (read up on colrorspcaes and see what PIL can convert to).

    ReplyDelete