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

Gopichandh Danala
Gopichandh Danala 2017년 6월 2일
편집: Gopichandh Danala 2017년 6월 2일
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.
Tinna Armasamy
Tinna Armasamy 2017년 6월 2일
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

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

도움말 센터File Exchange에서 Agriculture에 대해 자세히 알아보기

질문:

2017년 6월 2일

댓글:

2017년 6월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by