Function and GUI error!!

I am doing a GUI on soil image processing. Following are the task need to be performed by my GUI.
1)Upload image
[filename pathname]=uigetfile({'*.jpg';'*.tif'});
soil=strcat(pathname,filename);
axes(handles.axes1)
imshow(soil)
2)Image to be converted to binary image
soilgray=getimage(handles.axes1);
soilgray=rgb2gray(soilgray);
level=graythresh(soilgray);
im=im2bw(soilgray,level);
axes(handles.axes2);
imshow(im);
3)Find connected components of each particle in the soil
cc = bwconncomp(im,8);
n= cc.NumObjects;
set(handles.text11,'String',n);
4)Use region props to find the area,diameter and major axis length of each particle
Area = zeros(n,1);
Diameter = zeros(n,1);
MajorAxis = zeros(n,1);
Sand = zeros(n,1);
Silt = zeros(n,1);
Clay = zeros(n,1);
k = regionprops(cc,'Area','EquivDiameter','MajorAxisLength');
numClayParticles = 0;
numSiltParticles = 0;
numSandParticles = 0;
5)Do for loop to classify each particle size whether it is clay, sand or silt based on the size of the diameter
for m=1:n
Area(m) = k(m).Area;
Diameter(m) = k(m).EquivDiameter;
MajorAxis(m) = k(m).MajorAxisLength;
if Diameter(m) < 0.0236
Clay(m)=Diameter(m);
numClayParticles = numClayParticles + 1;
elseif Diameter(m) >=0.0236 && Diameter(m) < 0.5906
Silt(m)= Diameter(m);
numSiltParticles = numSiltParticles + 1;
elseif Diameter(m) >= 0.5906 && Diameter(m) < 23.6220
Sand(m) = Diameter(m);
numSandParticles = numSandParticles + 1;
end
end
6)From the number of type of particles from the for loop, calculate the percentage of clay,silt and sand
ClayPercentage = (numClayParticles/n)*100;
set(handles.text15,'String',ClayPercentage);
SiltPercentage = (numSiltParticles/n)*100;
set(handles.text16,'String',SiltPercentage);
SandPercentage = (numSandParticles/n)*100;
set(handles.text17,'String',SandPercentage);
7)This is done to determine the type of soil based on the USDA Soil classification triangle based on particle size of soil image
I have done the coding but I am unable to perform the for loop accurately and not getting accurate result.I have problem from step 5 onward.Please help with the coding above! Thank you!

3 Comments

You didn't attach any image for reference to check. I just looked at the code and pointing some plausible mistakes.In step-5, you have 'n' number of elements in all three particles making some zeros in each array of clay, silt and sand. I am assuming the sum of three should be equal to n, not each holding n elements in it. Just remove zero elements from each vector at the end
Clay(Clay == 0) = [];
Silt(Silt == 0) = [];
Sand(Sand == 0) = [];
Your percentages should be correct, verify if you are getting:
numClayParticles + numSiltParticles + numSandParticles = n
Finally, Why does your last elseif have two conditions?
elseif Diameter(m) >= 0.5906 && Diameter(m) < 23.6220
You said there are only three things in your image, is anything bigger than 23.6220 a background? If so you are still counting them in your total objects (n) and using it for computing percentages. Maybe this is something worth checking.
I will correct the error. Meanwhile, attached is the sample image. Thank you for the assistance.
I ran through your code on my system for the above image and I got
numClayParticles = 0;
numSiltParticles = 0;
numSandParticles = 85;
whereas n = 86..
I think your problem is with the segmentation itself, I don't think you are able to get proper segmented results, check segmentation

Sign in to comment.

Answers (0)

Categories

Find more on Agriculture in Help Center and File Exchange

Asked:

on 2 Jun 2017

Community Treasure Hunt

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

Start Hunting!