Login  Register

How to cut an image into image parts ?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options Options
Embed post
Permalink
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

How to cut an image into image parts ?

rajava
I am trying to write a macro to cut a simple line drawing image into image parts. I am trying to use the wand tool and cut but it doesn't seem to work. The is the sample image
Here is the code i was trying ,
open("http://www.coloringparty.eu/images/zoom/toddlers/viewsize/Rocket-toddlers.gif")
doWand(177, 478);
run("Cut");
doWand(338,321);
run("Cut");
Also, Is there a way to find a point(x,y) to doWand so that it comprises of a part and find as much part as possible programmatically ? Any help is this matter is greatly appreciated, Thanks.


Cut image should something like this , but this was cut using wand manually,
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: How to cut an image into image parts ?

edsimmons
rajava wrote
I am trying to write a macro to cut a simple line drawing image into image parts. I am trying to use the wand tool and cut but it doesn't seem to work. The is the sample image
Here is the code i was trying ,
open("http://www.coloringparty.eu/images/zoom/toddlers/viewsize/Rocket-toddlers.gif")
doWand(177, 478);
run("Cut");
doWand(338,321);
run("Cut");
Also, Is there a way to find a point(x,y) to doWand so that it comprises of a part and find as much part as possible programmatically ? Any help is this matter is greatly appreciated, Thanks.


Cut image should something like this , but this was cut using wand manually,
Hi,

You could start by trying something like Find Maxima.
Using the image you linked to, I got good results with:

run("Find Maxima...", "noise=60 output=[Point Selection] exclude");
roiManager("Add");
run("Set Measurements...", "  centroid display redirect=None decimal=3");

r=nResults();
//Label=newArray(r);
X=newArray(r);
Y=newArray(r);
d=newArray(r);
for(i=0;i<r;i++) {
        selectWindow("Rocket-toddlers.gif");
        X[i]=getResult("X",i);
        Y[i]=getResult("Y",i);
        doWand(X[i],Y[i]);
        run("Cut");
            newImage(i, "8-bit White", 400, 400, 1);
        run("Paste");
}

Hows that for starters?

Best,
Ed
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: How to cut an image into image parts ?

edsimmons
<quote author="edsimmons">
Hi,

You could start by trying something like Find Maxima.
Using the image you linked to, I got good results with:

run("Find Maxima...", "noise=60 output=[Point Selection] exclude");
roiManager("Add");
run("Set Measurements...", "  centroid display redirect=None decimal=3");

r=nResults();
//Label=newArray(r);
X=newArray(r);
Y=newArray(r);
d=newArray(r);
for(i=0;i<r;i++) {
        selectWindow("Rocket-toddlers.gif");
        X[i]=getResult("X",i);
        Y[i]=getResult("Y",i);
        doWand(X[i],Y[i]);
        run("Cut");
            newImage(i, "8-bit White", 400, 400, 1);
        run("Paste");
}

Hows that for starters?

Best,
Ed
</quote>

Really sorry, missed a bit in the macro... here it is again, this time actually working properly.

run("Find Maxima...", "noise=60 output=[Point Selection] exclude");
roiManager("Add");
run("Set Measurements...", "  centroid display redirect=None decimal=3");
run("Measure");
r=nResults();
X=newArray(r);
Y=newArray(r);
d=newArray(r);
for(i=0;i<r;i++) {
        selectWindow("Rocket-toddlers.gif");
        X[i]=getResult("X",i);
        Y[i]=getResult("Y",i);
        doWand(X[i],Y[i]);
        run("Cut");
        newImage(i, "8-bit White", 400, 400, 1);
        run("Paste");
}

Hope that helps,
Ed
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: How to cut an image into image parts ?

Michael Schmid
In reply to this post by rajava
Hi rajava,

You need two things:
(1) the image with the background not appearing as an object.
(2) a Wand that can omit interior holes. You can use the Versatile  
Wand from
   http://imagejdocu.tudor.lu/doku.php?
id=plugin:segmentation:versatile_wand:start

Assuming pixel (0,0) is background:

run("RGB Color");
run("8-bit");
setAutoThreshold("Default dark");
run("Apply LUT");
run("Versatile Wand", "value=0 color=0 gradient=0 connectedness=8-
connected x=0 y=0 do");
run("Clear", "slice"); //surrounding should be background
run("Select None");
run("Find Maxima...", "noise=0 output=List light");

Then have a loop and run the wand with the x and y coordinates of  
each line in the Results Table, Duplicate and 'Clear Outside' in the  
new image; then select the original again for selecting the next part.

Note that "Find Maxima..." always reports the position of a  
foreground pixel of the object, it will never give you the position  
of an inner hole or even a pixel.
An alternative would be "Analyze Particles" with "Record Starts" on,  
then use the XStart and YStart for the wand.


Michael
________________________________________________________________

On 26 Sep 2011, at 13:34, rajava wrote:

> I am trying to write a macro to cut a simple line drawing image  
> into image
> parts. I am trying to use the wand tool and cut but it doesn't seem  
> to work.
> The is the sample image
> Here is the code i was trying ,
> open("http://www.coloringparty.eu/images/zoom/toddlers/viewsize/ 
> Rocket-toddlers.gif")
> doWand(177, 478);
> run("Cut");
> doWand(338,321);
> run("Cut");
> Also, Is there a way to find a point(x,y) to doWand so that it  
> comprises of
> a part and find as much part as possible programmatically ? Any  
> help is this
> matter is greatly appreciated, Thanks.
> http://imagej.588099.n2.nabble.com/file/n6831553/Rocket-toddlers.gif
>
> Cut image should something like this , but this was cut using wand  
> manually,
> http://imagej.588099.n2.nabble.com/file/n6831553/imageparts.png
>
> --
> View this message in context: http://imagej.588099.n2.nabble.com/ 
> How-to-cut-an-image-into-image-parts-tp6831553p6831553.html
> Sent from the ImageJ mailing list archive at Nabble.com.
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: How to cut an image into image parts ?

rajava
In reply to this post by edsimmons
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.



Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: How to cut an image into image parts ?

edsimmons
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
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: How to cut an image into image parts ?

rajava
Hi Ed,
     thanks for the explanation, it really helped, but i have to modify this line to ,

 doWand(X[i],Y[i],10.0, "8-connected"); // run the wand tool at the location of interest from

from:

 doWand(X[i],Y[i]); // run the wand tool at the location of interest

to make it work.

These are some problem iam facing now,

1) I need to cut the part all the way to the outer edge so that that entire part is cut and not get included when i gut the bigger part of the image that might include this part. How do i do it ?

2) Is there any way to find the size  ( no. of pixels) of the cut part so that i can start cutting from the smallest part to the largest part which might work well to cut a finite distinct number of parts out of the image ?

Any help in this matter is appreciated.