How to set the value for thresholding for detecting trees in Matlab?
I am new in Matlab. I have a picture which includes a building,a person, a small river and some trees. I need to threshold the green band (I guess) to detect trees with erosion dilation etc. However, I can't seem to even make an histogram of the image's colors. All the other objec开发者_如何学Pythonts in the picture also have some green in it I think (i used myImage(:,:,2) < 130 ) and not only greens, but almost all the other objects were there in the binary picture (the person's black coat, river etc.). Can you tell me a way to do this? I want to get a histogram first, not sure how to use it though.
myImage = imread('myIm.JPG');
?? imhist(myImage); doesn't work.
Any help would be appreciated.
If I even manage to get an histogram, how can I use it to detect the trees? Can I both threshold green and other colors?
You probably want to first convert your image into another color space, like the HSV. You could do something like:
myImage = imread('myIm.JPG');
hsv_myImage = rgb2hsv(myImage);
imhist(hsv_myImage(:,:,1)); %just look at the hue component of the image
Then your histogram will indicate all the different hues.
use the hist() function in matlab for color images
精彩评论