Login  Register

Re: How to cut an image into image parts ?

Posted by edsimmons on Sep 27, 2011; 12:00pm
URL: http://imagej.273.s1.nabble.com/How-to-cut-an-image-into-image-parts-tp3682979p3682983.html

rajava wrote
Wow ! that really worked for that image Thank you very much for the macro, i was trying to apply the same macro to another simple image but lines that are but doesn;t seem to be fine as shown, i think i am not adjuting the noise level or something, bare with me since this image processing are pretty new to me ,

To kind of apply for similar line drawing image what paramertes should i change to see so that i can get a better cut of image parts, ? Please advise.



Hi Rajava,

I'm glad to hear that worked out for you on the first image.

To hep you get the idea of what is going on here I've added a few notes to the macro:

if (nImages>0) {
title = getTitle(); // get the title of the active image
run("Clear Results");
run("Find Maxima...", "noise=60 output=[Point Selection] exclude"); // find the maxima points in the image and mark the locations with point selections
roiManager("Add");
run("Set Measurements...", "  centroid display redirect=None decimal=3"); // configure the behaviour of measure
run("Wand Tool...", "mode=8-connected tolerance=10"); // set up the wand tool
run("Measure"); // actually do the measurement
r=nResults(); // collect the number of results
X=newArray(r);
Y=newArray(r);

for(i=0;i<r;i++) {
   // iterate through all the results
        selectWindow(title); // choose the window with the source image
        X[i]=getResult("X",i); // get the X and Y locations of the result
        Y[i]=getResult("Y",i);
        doWand(X[i],Y[i]); // run the wand tool at the location of interest
        run("Copy"); // copy the reult
        newImage(i, "8-bit White", getWidth(), getHeight(), 1); // create a new image
        run("Paste");
}
}

The png you first provided had much less noise and was higher resolution than these new images. 4.jpg has no white border around the image and has thin and broken lines making up some of the shapes. You can make life easier by making sure you're using the highest resolution images with lowest noise possible. If you look closely at the edges of the features in the image 4.jpg there is a lot of speckly noise. Touching up broken lines might be all that is needed to get this to work on some images where areas join together.

To get a better idea of the find maxima step, try opening an image and the clicking Process->Find Maxima. Tick the Exclude Edge Maxima and Preview Point Selection boxes, set Output Type to Point Selection and then adjust the noise tolerance value and observe the changes in the selected points.

When/if you get the resutls you're looking for with find maxima, try setting the noise value in the macro accordingly and try it again. I've made a few little adjustments to the macros so it should be a little better at dealing with noisy images.

Michael's suggestion of the Versatile Wand is a very good idea, thanks!
I tried thresholding the image first, then find maxima behaves as Michael mentioned. However I get very good results with find maxima with the original image like so:
run("Find Maxima...", "noise=45 output=[Point Selection] exclude"); // noise of 45-60 works well here
This reliably selects the midpoints of the 'holes' in the image.

I hope this helps,

Best,
Ed