How to get mask matrix from ROI

I get a ROI from a image by

aRoi =  ips.getRoi;
aSizeX = ips.getWidth;
aSizeY = ips.getHeight;

Then I create a empty imageplus:

ips_new = ij.IJ.createImage('plate',aSizeX,aSizeY,1,8);
ips.setRoi(aRoi);
aMask = aRoi.getMask.getFloatArray == 255;

I want to get a 2D mask of the same size with [aSizeX,aSizeY], but I found that the size of aMask is much smaller than the image size.

Is there a way to get the mask with correct size?
Thanks

Not entirely sure about your workflow, but the first thing I would recommend checking is whether you have handled all of your conversions between pixels and microns (assuming there is image metadata). You do not describe where your sizes are coming from.

I think you want to fill the ROI in your newly-created image.

From memory, it may be something like this:

ips.setValue(255)
ips.fill()

Here, it seems that instead you are requesting a mask from the ROI - which I believe will create an entirely new ImageProcessor based on the ROI bounding box. And totally ignore the image you just created.

1 Like

Yes, you are right.
I find the source code of Generate Mask command, and the key step is the

ips.setValue(255)
ips.fill()