You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
Problem understanding image processing tool
1 view (last 30 days)
Show older comments
Hi, i am new to MATLAB image processing.
I want to carry out my B.Tech project with regard to the determination of "Moisture Content" using image processing & in this regard i downloaded a research paper
An approach to estimate moisture content of apple with image processing method by Farshad Vesali, Masoud Gharibkhani and Mohmmad Hasan Komarizadeh
I was successfully able to generate the BW image as given below by using the help of the video "image processing made easy" video on the MATLAB site but i am unable to understand how to get the values of zi for using in equations 1 through 7 as shown in the images below and am not able to understand the paragraph just after the equations.
So, if anyone of you may be interested in helping me out i understanding these equations and helping me in using MATLAB Image Processing toolbox please post a REPLY as soon as possible as i have to report the project on Monday.
Thanks
If you can help me on Facebook or SKYPE also through video chat also.
Accepted Answer
Image Analyst
on 19 Apr 2014
Edited: Image Analyst
on 21 Apr 2014
Well I did the masking part of your B.Tech project for you in http://www.mathworks.com/matlabcentral/answers/126363#answer_133893. I imagine you'll need to do some of the project yourself, so programming in those 5 equations seems simple enough. I'll give you the first two as a freebie:
I = mean2(grayImage);
v = var(grayImage);
S = 1 - (1 / (1+v));
pz is the pdf, which is the normalized histogram so
[pz, z] = imhist(grayImage) / numel(grayImage);
I trust that, knowing that, you can do equations 5, 6, and 7 yourself, right?
38 Comments
Image Analyst
on 19 Apr 2014
Please format your code. This will show you how: http://www.mathworks.com/matlabcentral/answers/13205-tutorial-how-to-format-your-question-with-markup
What is untitled.png? Can you attach that. And what are the two images you are having to decide between, and how will I know if I've chosen the correct one? What is the criteria for success?
Saqib
on 20 Apr 2014
Edited: Saqib
on 20 Apr 2014
Above i have pasted the fully formatted code that i have been able to generate till now assuming MSE1 is the zi taken in the equation & PSNR is p(zi) as taken in the above equations. Now i just wanted to know whether i am doing the right thing or the wrong. Basically i want to estimate moisture content using the above equations and use the same in ANN but i don't actually know how to correlate the two and how to obtain the zi & p(zi) from the images And also i was asking whether the author of the paper has derived zi & p(zi) from Fig1 (A&B) or Fig 3 (A&B)
Image Analyst
on 20 Apr 2014
Edited: Image Analyst
on 20 Apr 2014
They got them from the M image, which is shown in figure 1, though that's zoomed in on a small area and not showing the entire M image.
z is the histogram like I said. You can tell by looking at the equations. z(i) is the counts at gray level (i-1). It is not the MSE. Not sure why you'd think that - just look at the equations for mean gray level and entropy and you can tell that z is the histogram counts.
Image Analyst
on 20 Apr 2014
I don't know what line 59 is. Please give the full error message - all of it, ALL the red text. Don't snip out a small chunk of it. I need traceback lines of code and everything. Unfortunately, now you'll have to wait until tomorrow because I'm headed to bed.
Saqib
on 20 Apr 2014
Meanwhile can we start from the beginning so i understand he whole process easily by getting M images from the main image & processing it to use it i the equations above so its easy & fast & no time is wasted on non-necessary stuff as i user a lot of time in finding MSR and finalyy laernt that it is of no use as it is not used in the equations above. Thanks
Image Analyst
on 20 Apr 2014
That line 59 is not what's causing the error. I don't know how many more times I'll be willing to ask "Please give the full error message - all of it, ALL the red text. " or how long I'll be willing to wait if you don't help me to help you. You have NOT yet posted the full error message, though you think you did. There is still some red text with the traceback that you did not copy here.
Image Analyst
on 20 Apr 2014
I thought you had a script. I didn't know you were doing it the hard way by typing everything into the command line. It says that the input argument to var() must be double, so make it double:
v = var(double(grayImage));
Image Analyst
on 20 Apr 2014
v is a vector. If you want the variance of the whole image instead of column-by-column, use (:)
v = var(double(grayImage(:)));
Saqib
on 20 Apr 2014
Edited: Saqib
on 20 Apr 2014
thanks a lot.
which one is better to use? whole image or column by column... (please tell me from the equation)
this is about zi
Now can you help me with p(zi)
& how do i extract only the aple portion from the Untitled.png image so that i can exactly get it going.
Image Analyst
on 20 Apr 2014
They probably want the variance of just the masked apple area, so you'd do:
varianceOfAppleOnly = var(double(grayImage(appleMask)));
To get the histogram with the apple region only:
counts = hist(grayImage(appleMask), 256);
Image Analyst
on 20 Apr 2014
I don't know what you called it. What did you call the binary image that defines apple and not apple? Did you call it mask, foreground, binaryImage, or something else? Whatever you used, use that name.
Image Analyst
on 20 Apr 2014
It was called "mask" there, so use that.
varianceOfAppleOnly = var(double(grayImage(mask)));
counts = hist(grayImage(mask), 256);
I'm afraid you don't understand the concept of a mask or else you would have known this. Basically a mask is a logical array that says where to use elements from the array, and where to ignore elements. If the value is true or 1, it will use those elements, and if the value is false or 0, it won't use that. So when you say grayImage(mask) it only uses the pixels from grayImage that are white when you display the mask and it won't use any pixels from the parts of the mask that look black. Does that explain it enough? If you're still unsure, let me know and we can try to work up some simple examples with small arrays.
Saqib
on 20 Apr 2014
Edited: Saqib
on 20 Apr 2014
i used the code
varianceOfAppleOnly = var(double(grayImage(mask)));
counts = hist(grayImage(mask), 256);
but it shows this error
??? Index exceeds matrix dimensions.
Ys i understood mask a lil bit.
N sir can you please answer a little bit faster please as its already 11pm here & i have to go to sleep ater half an hour and when i am back then u have to go to sleep
Image Analyst
on 20 Apr 2014
Do this
whos grayImage
whos mask
[rows, columns, numColors] = size(grayImage);
[rowsm, columnsm, numColorsm] = size(mask);
what do you see?
Saqib
on 20 Apr 2014
Edited: Saqib
on 20 Apr 2014
Name Size Bytes Class Attributes
grayImage 369x304 112176 uint8
Name Size Bytes Class Attributes
mask 369x304 112176 logical
& now its showing this error
??? Error using ==> times
Integers can only be combined with integers of the same class, or scalar doubles.
Error in ==> hist at 78
xx = miny + binwidth*(0:x);
Image Analyst
on 20 Apr 2014
Try casting grayImage when you send it into hist().
Saqib
on 20 Apr 2014
how?
also please can you help me with p(zi) now - waht it is & how to obtain it.
and what is the "L" used i the equations above.
Thanks.
I'll be back after nearly 10 hrs from now as i have t go to bed.
So please post the reply on all the three issues.
Thaks a lot.
Image Analyst
on 20 Apr 2014
Edited: Image Analyst
on 20 Apr 2014
How? Just like with the others.
[z, grayLevels] = imhist(double(grayImage));
Sorry I can't do it all for you. First, I don't have time. Second, you didn't attach your code or images. And third, it's YOUR project and I'm pretty sure your professor is not saying "Please get someone on the web to code up this paper for you, so you can turn in their work as your own."
Saqib
on 20 Apr 2014
sorry but i m not asking you to do it all
i have to use all the corresponding values derived from here in neural networks and my professor gave me the chance of getting xternal help regarding imahe processing as i have never done it before. also i cant understand on how to get the values as i dont rven know what the values ate and its basically done on the images of the paper and i have to capture and generate the whole data myself. so i wanted help with this part ANN and rest i will do myself. so if yoiu wish' help me a bit more bdw thanks for all the help till now
Image Analyst
on 20 Apr 2014
I don't know neural networks so either Greg or your professor can help there. Hopefully you're getting the histogram now.
Image Analyst
on 21 Apr 2014
count is a histogram , not an image . You should display it with bar() not imshow().
And I wouldn't do both and I wouldn't use imhist on a double image unless you want to make sure it's in the range 0-1. It's easier to use hist() on a double image.
Image Analyst
on 21 Apr 2014
Just asking later doesn't mean I forgot what I said earlier: " I imagine you'll need to do some of the project yourself, so programming in those 5 equations seems simple enough. I'll give you the first two as a freebie". If I do all the equations for you, then you will not have done enough yourself for your project. Like I said they're simple. You almost type them out exactly as they appear. Please make an attempt. It's not that hard. There is a function called sum() you know.
Saqib
on 21 Apr 2014
I would have done it myself but i haven't read MATLAB.
So, i was able to understand a little bit about the program.
So, i was searching online help.
Also i have to do image capturing & Neural Network etc. myself plus the manual determination. So these 5 equations form a very small part o the entire project
Image Analyst
on 21 Apr 2014
I'll give you another two;
[pz, z] = imhist(grayImage) / numel(grayImage);
U = sum(pz.^2);
e = -sum(pz .* log(pz));
That leaves only one simple equation left for you to do . Tell me what you got for it.
Image Analyst
on 22 Apr 2014
Edited: Image Analyst
on 22 Apr 2014
Use ./ instead of /
And, no that's not the equation. You aren't even cubing it and don't have a multiplication sign.
Image Analyst
on 22 Apr 2014
Sorry, shouldn't have tried it all in one step. Needed 2 lines of code to do it. Try this:
[pz, z] = imhist(grayImage); % pz is the counts.
% Normalize so that the area under the curve = 1.
pz = pz ./ numel(grayImage);
Image Analyst
on 22 Apr 2014
Looks like you need to use the log conversion functions to get log to the base 2, which is not in MATLAB. Also you need to make sure pz if not zero for any value because the log of that is -infinity.
More Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Tags
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)