How to find the max and min of a shape? and mask the image based on that?

Here are the steps I need to do: find the max and min of pixels in the image (yellow lines in the image)
then I need to find the red lines that make the rectangle formed by yellow lines half.


then I need to mask the image so I have only one segment of the whole image and the rest become black as shown in the image:

I need a guide to do these steps.
Many thanks

Hi,
the main steps you need to do are:

  • Convert the image to 8 or 16 bit (Image>Type>8-bit)
  • Set an auto-threshold that separates your object from the background (Image>Adjust>Threshold)
  • Create a roi (selection) containig your object (Edit>Selection>Create Selection)
  • Measure the roi to get the coordinates, width and height of the bounding box of your object (Analyze>Measure). The interesting columns in the Results table are BX, BY, Width and Height. Make sure that Bounding Rectangle is selected under Analyze>Set Measurements.
  • Create a roi with the upper left corner at BX + Width / 2, BY, the width Width /2 and the height Height/2 (Edit>Selection>Specify)

You can execute the above steps manually and record them using the macro recorder (Plugins>Macros>Record). You only need to add a step to read the bounding rectangle data (BX, BY, Width and Height) from the results table ( getResult("Column", row)).

Best regards,
Volker

2 Likes

I forgot, once you have the roi you can use Edit>clear outside to remove the rest of the image, but you probably don’t need it, since you already have the roi and can just measure what is inside.

1 Like