views:

59

answers:

2

It's from this thread but I'm also interested in this.

  1. How to I filter out pixels not in green channel?
  2. And how to I select a point which is inside a closed box with MATLAB?

alt text

+1  A: 

For your two questions:

  1. Colored pixels have red, green, and blue color components. Selecting pixels based on their color involves selecting how much of each RGB component is present in the pixel. For example, a pure white pixel has each color component at its maximum (1 if the image type is double precision, 255 if the image type is uint8). You can look at my solution to the referenced question to see one way you can select pixels based on their RGB components. You can also check out this MATLAB documentation for more information about images and their data types.

  2. One way to select a point is to let the user select it using the GINPUT function. For example, the following will let the user select 1 point from the current axes, returning the x and y coordinates where they click:

    [x,y] = ginput(1);
    
gnovice
No user interaction is allowed...
wamp
+1  A: 

For the first question, @gnovice's answer should suffice.

For the second question: Use a Monte Carlo approach: have the algorithm choose a random pixel using RANDI (you may want to search within, say, 20 pixels of the center of the image to avoid problems with the border). If it's a green pixel, you try again. If it's a white pixel, you are inside one of the squares.

Jonas