Hi Avi,
as far as I can see, the built-in command Edit>Selections>Scale uses floating-point coordinates, so I don't understand the need of reimplementing it as a macro. The macro will be also less versatile than the built-in command since some selection types cannot be represented as a polygon.
Anyhow, it depends on what you define as center of the roi.
It's easy when assuming the center of the bounding box (as far as I understand, the built-in command also does this)
getSelectionBounds(x, y, width, height);
xmid = x + width/2;
ymid = y + height/2;
and then
x[i] = xmid + (x[i]-xmid) * factor;
y[i] = ymid + (y[i]-ymid) * factor;
Michael
________________________________________________________________
On Mar 20, 2015, at 15:51, Avi Leftin wrote:
> Hi,
>
> I am trying to write a macro that scales a freehand ROI in place multiple times on an image.
>
> I would like to use a command such as the following:
>
> run("Scale... ", "x=0.80 y=0.80 centered");
>
> However, in my macro I want to be able to input double/numeric values for the x and y scale factors, while leaving the center position fixed in order to use a loop.
>
> I found the following code snippet online that allows numeric scale factors for ROI:
>
> function scaleROI(factor) {
> type = selectionType();
> getSelectionCoordinates(x, y);
> for (i = 0; i < x.length; i++) {
> x[i] = x[i] * factor;
> y[i] = y[i] * factor;
> }
> makeSelection(type, x, y);
> }
>
> This does work but does not have a variable specifying the ROI center. Therefore, the ROI is scaled, but shifted because the center coordinates are also transformed.
>
> Any suggestions?
--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html