This gives you a bitmask. You can determine the bounding box of the mask and extract that portion of the original image. The pixels that arenot in the mask butare in the bounding box, you set to an arbitrary value, and then you take care how you interpret the counts involving that arbitrary value.
Usingimpoly in interactive mode does not allow for you to limit the user to a certain number of datapoints. If you know that you want an aligned rectangle, you could useimrect, but I'm guessing that's not what you're looking for.
You could make your own function relatively simply usingginput, which does allow you to put a limit on the number of clicks. Or you call it in a loop and draw lines between the points in between each click.
Best Answer