Login  Register

Re: run("Enlarge...", "enlarge=-1"); when touching edge of field

Posted by Gabriel Landini on Sep 24, 2007; 8:26am
URL: http://imagej.273.s1.nabble.com/run-Enlarge-enlarge-1-when-touching-edge-of-field-tp3698339p3698341.html

On Sunday 23 September 2007 20:13:13 Michael Cammer wrote:
> I have found that using the run("Clear Outside"); command in a macro
> sometimes leaves a few pixels at the edge of the selection.
>
> Therefore, I want to shrink the region of interest by one pixel before
> clearing.  So I tried run("Enlarge...", "enlarge=-1");
>
> The problem is that there is always at least one part of the ROI touching
> the edge of the image, so the error "Cannot shrink selections touching
> image edge" is returned.

What about i this:

enlarge your canvas by 1 pixels in all directions (i.e. 2 pixels larger,
centred),
restore the ROI (because it will get deleted when resizing)
shrink your ROI
reduce your canvas by 1 pixel in all directions
restore ROI.

In a macro, asuming you have a 256x256 image with a ROI touching the border:

run("Canvas Size...", "width=258 height=258 position=Center zero");
run("Restore Selection");
run("Enlarge...", "enlarge=-1");
run("Canvas Size...", "width=256 height=256 position=Center zero");
run("Restore Selection");

I hope it helps,

Gabriel