Calibrating mask for for accuracy

I have the following images.

I'm trying to mask the green part only using the code:

LCC = imread('1.jpg');
test_mask = LCC(:,:,2) > 175;  %same setting for both images

Though the calibration is already at 175, I'm still getting white spots when using imshow(test_mask)

Or is there a way to remove the noise (white spots) in the background and make the background "pure black"? Thanks

 Accepted Answer

Image Analyst
Image Analyst on 21 Dec 2013
You need to adjust the thresholds. Look at this custom demo I wrote for you (attached).

23 Comments

thank you very much for this. It helps a lot.
By the way, can you help me with the calibration of this program: https://www.dropbox.com/s/oq6nx1r9cg0ikh3/Nitrogen%20Def.rar
All the images that I used are already there. My program is already working but I'm not getting accurate results. The 10 leaf images included is supposed to be Panel 4 but when I run it on my program, it gives me an output of sometimes Panel 2, sometimes Panel 3. I've already tried calibrating the mask for both the LCC and the Test images but still the same result.
Thanks
Hi Walter, I'm now after for getting an accurate results. My program is already working but the result is not accurate
It is time for me to head to sleep, sorry.
It's okay sir. Thanks again. Have a good night.
What is the result? By the way, it's hard to follow the conversation and stay current when you're carrying it on in multiple discussion threads.
I already made another thread for the accuracy of my program. Here it is: http://www.mathworks.com/matlabcentral/answers/110450-increasing-the-accuracy-of-my-program
I guess you missed my prior comment. Anyway many people don't have programs to open the shareware rar file type. Zip is universal.
Elvin
Elvin on 26 Dec 2013
Edited: Walter Roberson on 26 Dec 2013
I just include 5 test images since my upload speed is so slow.
So, does this zip contain 5 of the 10 leaf images that are supposed to be Panel 4 but when you run it on your program, it gives you an output of sometimes Panel 2, sometimes Panel 3 instead of panel 4? And does it also contain all of the standard panels, and your m-file? If so, I may look at it tomorrow.
Yeah. All files that are needed are already there. We took those pictures around 8AM to 9AM with natural lighting. I don't know if that will have a big impace with the results. I also tried calibrating the masks hoping that it will give an accurate results, but nothing happened.
Anyway, thanks in advance and happy holidays. :)
As long as all the standards were taken with the same color light and same exposure level it should be okay. If not, then it's possible that they could get matched to the wrong standard.
we made sure that all images were taken with the same lighting and exposure.
By the way, I also uploaded some 5 images from Panel 2, and Panel 3. This might be helpful in helping me with the accuracy of my program. Here are the images: https://www.dropbox.com/s/jfu1qcmaf1ky2me/Test%20Images.zip
Thank you very much
I just haven't had a long enough block of time to look at this yet. Maybe this weekend.
It's okay. I can wait. Thanks again :)
Image Analyst
Image Analyst on 29 Dec 2013
Edited: Image Analyst on 29 Dec 2013
I made lots of improvements. See attached code. I only ran it on images 1-4. If you have any problems with some other image, let me know.
It could be more robust, like not expecting certain numbers in the filenames, etc. but it works.
thank you very much for that. That is really a big help. But I still can't detect the panel 4. I tried running the test image from panel 4 but the result said that it is closest to panel 2.
What is the test image from panel 4's filename? And I assume the panel 2 filename is LCC4.jpg. What were the delta E's between that image and all the standard LCC panels?
LCC1.jpg is Panel 2. LCC2.jpg is Panel 3. LCC3.jpg is Panel 4. LCC4.jpg is Panel 5. All test images are named 1.jpg to 10.jpg. I also uploaded test images from panel 2 and 3: https://www.dropbox.com/s/jfu1qcmaf1ky2me/Test%20Images.zip
I ran the program again using the test images from the folder naemed Panel 4. If the program is accurate this should give a result should be "The test image is closest to standard LCC Panel Image LCC3.jpg." since LCC3.jpg is Panel 4. The result the program is giving me is "The test image is closest to standard LCC Panel Image LCC2.jpg."
Here are the DeltaE's:
37.2280121817004
32.4103920945411
46.3183587550614
42.5523817009365
No, it's not. You're not realizing certain things. For one, the blades are a lot brighter than you think they are. In fact when we look at the RGB values of both the standards and test images:
standardMeans =
160.214758458431 197.181622129674 58.9798316015043
151.791390004578 172.326893656249 103.610183415117
140.489793180539 156.166890704425 117.035337936326
153.707747416186 161.159521297862 136.795286601503
testMeans =
169.575414791022 212.304643393041 133.444469974054
183.017321075119 228.922035175274 136.424941826779
152.051015834026 199.078477650428 110.05266640506
160.274121743674 207.052936770004 129.50083587363
161.01396762605 207.530082395828 126.591355056847
we see that the test means are bright. For example they are all at least 199 in the green. Now, which standard is that bright? The first one, not the second one. True, the second one may be a better match than the first one if you looked at just the hue and saturation, but if you include the lightness(value) the first one is a better match. There is also a problem with your standards in that they have bright and dark ridges so they have a bimodal histogram. Perhaps you're just paying attention to the brighter color and that's why your eyes are deceiving you. I think it's because you don't have good control over your intensity. Or maybe you just need to, or want to ignore the differences in lightness and just look at the differences in a and b. You can calculate the differences in ab instead of E (which is l, a, and b) if you want to ignore intensity.
I've attached my new program which uses actual filenames, and has different folders for standard and test images, and also calculates RGB means for you to examine.
Thank you for the explanation. The staffs at the IRRI are the one who said that the following images belong to this/that panel. That's why it is already classified according to their panels. To tell you, they just look at the leaf and compare it with the LCC using only their eyes. We are basing the accuracy of our program based on the results that IRRI has given to us. So that's why I'm worried that I'm not reading the same results with the IRRI.
Anyway, I guess our problem is with the taking of the pictures. I guess we need to adjust the lighting properly. I guess we have to build a nice setup when taking pictures for both the LCC and the leafs.
By the way, thank you very much for the help. I'll take a look at the new program once I get home

Sign in to comment.

More Answers (1)

White is high in all of R, G, B, whereas the Green part that you want will be low in R or B (or both.) So you can test something like,
test_mask = LCC(:,:,2) > 175 & LCC(:,:,1) < 128; %128 chosen arbitrarily

2 Comments

I've tried it but I've got almost a pure black output
test_mask = LCC(:,:,2) > 100;
then bwopen() on test_mask.
You have a spot inside your leaf where the green channel goes as low as 110.
Your red channels turn out to be fairly high all over inside the leaf, including values as high as 224. The blue channel is generally notably lower than the red channel, but peaks as high as 247 (one bright spot right at the edge of the leaf, but over 240 in some other spots as well.)
Your leaf is not all "green": the white along the ribs and the white speckles elsewhere, are important to the overall appearance. You need to keep those white spots when they are inside the leaf, but an isolated white spot of the same intensity in the background needs to be removed. This suggests that although you should threshold based on color, that you should also be throwing away small points. Such as by using bwopen().

Sign in to comment.

Categories

Find more on Agriculture in Help Center and File Exchange

Tags

Asked:

on 21 Dec 2013

Commented:

on 2 Jan 2014

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!