필터 지우기
필터 지우기

kmeans image segmentation and confusion matrix

조회 수: 1 (최근 30일)
bayoishola20
bayoishola20 2014년 10월 4일
댓글: bayoishola20 2014년 10월 9일
A sample kmeans image segmentation code as well as for its confusion matrix would be greatly appreciated. Thanks. Note: For a non-grayscale image please.

답변 (1개)

Image Analyst
Image Analyst 2014년 10월 4일
See the Mathworks demo of using kmeans() on a color (3D) image: http://www.mathworks.com/products/demos/image/color_seg_k/ipexhistology.html
For the confusion matrix you need to know the "true" class for each pixel that was classified. There may be some function to do that in the stats toolbox that I'm not aware of, but if not it's easy enough to just scan the matrices and make it
confusionMatrix = zeros(numberOfClasses); % Initialize
for col = 1 : columns
for row = 1 : rows
% Find the row and column that these classes
% will have in the confusion matrix.
r = classifiedImage(row, column);
c = trueClassificationImage(row, column);
confusionMatrix(r, c) = confusionMatrix(r, c) + 1;
end
end
  댓글 수: 9
Image Analyst
Image Analyst 2014년 10월 7일
You need to create an image where you have 1 for pixels that are class 1, 2 where pixels are class 2, 3 where pixels are class 3, etc. I guess that should actually instead be
classifiedImage = BW_class_1;
classifiedImage(bw_class2) = 2;
classifiedImage(bw_class3) = 3;
classifiedImage(bw_class4) = 4;
classifiedImage(bw_class5) = 5;
classifiedImage(bw_class6) = 6;
bayoishola20
bayoishola20 2014년 10월 9일
After doing as mentioned in the last comment for the classifiedImage, I'm still unable to achieve the confusion matrix for the segmented image. I would love it if you could help summarize to finally achieve the confusion matrix. Thanks for the so much patience #Newbie

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

Community Treasure Hunt

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

Start Hunting!

Translated by