Filtering out pixels in the green channel with MATLAB, etc
It's from Stack Overflow question How do I calculate the area under a curve in an image with MATLAB?, but I'm also interested in this.
- How do I filter out pixels not in the green channel?
- And how do I select a point which is inside a closed box with MATLAB?
Alt text http://internationalpropertiesregistry.com/Server/showF开发者_如何学Pythonile.php?file=%2FUpload%2Fstatistics.gifc49ca28823a561a41d09ef9adbb5e0c5.gif
For your two questions:
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.
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);
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.
精彩评论