Transfering a selection

Dear ImageJ Users,

I’ve a quick question for you I could not figure out:

I want to transfer a selection i made in one image, to
another image.

When I use ImageJ this works, but in my macro not.
Sample code:

139       ....
140       run("Make Binary");
141       run("Convert to Mask");
142       saveAs("PNG", outputDir+inputFiles[i]+"_thresh_binary");
143       close();
144     
145       open(outputDir+inputFiles[i]+"_thresh_binary.png");
146       run("Create Selection");
147       
148       open(inputDir+inputFiles[i]);
149       run("Restore Selection");
150       run("Crop");
151       saveAs("PNG", outputDir+inputFiles[i]+"_thresh_binary_cropped");
152       close();

However, the cropping gives me the input image, not the image cropped to the selection as expected.
I’m somehow not seeing what I’m doing wrong here.

Hope you can help out,
best wishes,
Stephan

Args,

I apparently forgot that I should really be using “Clear Outside” inside of “Crop”. Correct?

best,
Stephan

Can you clarify what you want the result to be?

It sounds like you might want an image of the same dimensions as the original, preserving the parts of the original image that are positive in the binary image, with all other pixels set to 0. Is that right?

Here’s some code that does that with a sample image:

    run("Dot Blot (7K)");
    run("Make Binary");
    run("Create Selection");
    run("Dot Blot (7K)");
    run("Restore Selection");
    run("Clear Outside");
1 Like

Yes @tswayne,

I confused “Crop” with “Clear Outside” respectively “Clear”.
Using the latter two commands I can make it work,
thanks!

Best wishes,
Stephan

1 Like