0
$\begingroup$

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

$\endgroup$
1
  • $\begingroup$ Masking option. See documentation. $\endgroup$
    – ciao
    Feb 12, 2014 at 8:45

1 Answer 1

3
$\begingroup$

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.

$\endgroup$
3
  • $\begingroup$ 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. $\endgroup$ Feb 12, 2014 at 9:53
  • $\begingroup$ @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). $\endgroup$
    – ciao
    Feb 12, 2014 at 9:59
  • $\begingroup$ thank you very much.It works. Great!! $\endgroup$ Feb 12, 2014 at 15:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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