# How to get Binarize to ignore already set background

I have grayscale images which contain a clear foreground and background, which Binarize is easily able to split out. Then within the foreground, I want to binarize again, to find the area around the high point.

Here is an example image (modified from one of the examples in the help for RemoveBackground):

pepper = Import["https://i.stack.imgur.com/yX1jr.png"]


Now this image has a chili pepper, which is the brightest part, a few leaves and then an almost black background. I want to select just the chili, not the leaves too.

RemoveBackground will easily remove the black background and make it transparent if I wish,

pepper2 = RemoveBackground[pepper, Black]


Or I can set it to be non-transparent entirely black via:

pepper3 = ImageMultiply[pepper, Binarize[pepper]]


Having done that, I can't use Binarize (or FindThreshold) again, as it treats the background as still being there.

GraphicsRow[{pepper, pepper2, pepper3}]


How do I find the 'best' region around the point of highest intensity? If I can clip the image sufficiently that the actual background is entirely removed, Binarize will work fine and give me a nice looking region.

My actual images look something more like this:

which you can see from a 3D plot has a well-defined bump, that I wish to characterise.

actual = Import["https://i.stack.imgur.com/CMbiE.png"]
ListPlot3D[ImageData@actual, ImageSize -> 800]


• I don't suppose you want to just use RemoveBackground before your binarize? – Carl Lange Apr 8 at 7:59
• @CarlLange, RemoveBackground just sets the background to have an alpha channel, which ImagePad actually does too (when the initial image has an alpha channel, as this one has gained when I uploaded it). – KraZug Apr 8 at 8:14
• Ah, hmm. I suppose ImageCrop with no arguments would also work. – Carl Lange Apr 8 at 8:15
• @CarlLange, my background isn't nice and uniform, so I can't just crop it out of the picture - the foreground can go towards the edge of the image in several different directions – KraZug Apr 8 at 8:17
• @KraZug you really need to formulate your problem properly --- especially posting the right original image you are working and the result you seeking. – Vitaliy Kaurov Apr 8 at 8:19