Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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

enter image description here

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: enter image description here

share|improve this question
    
Masking option. See documentation. –  rasher Feb 12 at 8:45

1 Answer 1

up vote 2 down vote accepted

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])];


masked = ImageApply[1 &, foto17, Masking -> mask];

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]]}]}]]

enter image description here

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:

enter image description here

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.

share|improve this answer
    
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 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). –  rasher Feb 12 at 9:59
    
thank you very much.It works. Great!! –  Michiel van Mens Feb 12 at 15:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.