# Image processing, masking

My question is about finding a object in a specific part of a image. For example, I use this image:

As you can see, you will se two persons walking on the field. I only want to find the second person on the right site of center line

If I use the following script, Mathematica find both.

Show[Image[picture1, ImageSize -> 600],
Graphics[{Red,
Table[Inset[ToString[i],
PixelValuePositions[foto17, {0.07, 0.09, 0.1}, .05][[i]]], {i, 1,
Length [
PixelValuePositions[foto17, {0.07, 0.09, 0.1}, .05]]}]}]];


Is there a way to select a specific part of a image? Fore example, something like this:

• Masking option. See documentation. – ciao Feb 12 '14 at 8:45

Here's a quick-n-dirty example, hand-tweaked values. You'll probably want to use more sophisticated means if you have more than a few images to process. You can also use the drawing tools to take your image and manually draw a mask. Many ways to skin this cat...

mask = 1 -
BoxMatrix[
Sequence @@ Reverse@({2, .8} Round[ImageDimensions[foto17]*.5])];

Show[Image[picture1, ImageSize -> 600],
Graphics[{Red,
Table[Inset[ToString[i],
PixelValuePositions[masked, {0.07, 0.09, 0.1}, .05][[i]]], {i, 1,
Length[PixelValuePositions[masked, {0.07, 0.09, 0.1}, .05]]}]}]]


Update per OP comment: As I said in comment, Michiel, you can use drawing tools to manually draw arbitrary masks. Here's one for the example:

I simply pasted a copy of the image, invoked the Drawing Tools via Ctrl-D or the Graphics menu, and drew the polygon. Replace the masked=... with masked= <the masked image>, and you're golden - you don't need the first line of my example that generated the simple rectangle mask.

As said, if you really want to get fancy, you can use the image processing morphological tools to find lines/create masks, you'll want to read up the documentation if you want to pursue that route.

• Hi,Thanks for your quick respons. In your approache you create a retangle. I would like to select everything right to the center line of the soccer field.So a part of the left side of the retangle is curved. – Michiel van Mens Feb 12 '14 at 9:53
• @MichielvanMens: You could find the lines in the picture using MMA image functions, use that to create polygon mask. As I commented, you can also "draw" an arbitrary mask. I'll see if I can whip one up as an example (it's late here, might be a delay, though others will reply I'm sure). – ciao Feb 12 '14 at 9:59
• thank you very much.It works. Great!! – Michiel van Mens Feb 12 '14 at 15:03