필터 지우기
필터 지우기

Using post classification confusion matrix

조회 수: 8 (최근 30일)
bayoishola20
bayoishola20 2014년 9월 19일
댓글: bayoishola20 2014년 9월 22일
Pls I need to perform confusion matrix, but I keep getting;
Error using confusion (line 43)
Targets and outputs have different dimensions.
The code I used is;
[c,cm,ind,per] = confusion(BW_1,new_image{1})
where;
BW_1=roipoly(my_image); %Trained class no. 1
BW_1 gives a (2592x4608 logical) variable value in the Workspace part
<2592x4608 logical>
new_image
new_image =
Columns 1 through 4
[7776x4608 uint8] [7776x4608 uint8] [7776x4608 uint8] [7776x4608 uint8]
Columns 5 through 6
[7776x4608 uint8] [7776x4608 uint8]
Kmeans Segmentation code used
he= imread('C:\Users\ISHOLA\Desktop\1.jpg'); %Reading image which is not gray
cform = makecform('srgb2lab');
lab_he = applycform(he,cform);
ab = double(lab_he(:,:,2:3));
nrows = size(ab,1);
ncols = size(ab,2);
disp(nrows);
disp(ncols);
ab = reshape(ab,nrows*ncols,2);
nColors = 6;
% repeat the clustering 3 times to avoid local minima
[cluster_idx cluster_center] = kmeans(ab,nColors,'distance','sqEuclidean','replicates',6);
pixel_labels = reshape(cluster_idx,nrows,ncols);
%figure, imshow(pixel_labels,[]), title('image labeled by cluster index');
segmented_images = cell(1,3);
rgb_label = repmat(pixel_labels,[1 3]);
for k = 1:nColors
color = he;
color(rgb_label ~= k) = 0;
segmented_images{k} = color;
end
new_image = cellfun(@(x)reshape(x,2592*3,4608),segmented_images,'UniformOutput',false)
  댓글 수: 3
bayoishola20
bayoishola20 2014년 9월 20일
okay!Thank you.
U r right, but below is the segmentation code I had used.
he= imread('C:\Users\ISHOLA\Desktop\1.jpg'); %Reading image which is not gray
cform = makecform('srgb2lab');
lab_he = applycform(he,cform);
ab = double(lab_he(:,:,2:3));
nrows = size(ab,1);
ncols = size(ab,2);
disp(nrows);
disp(ncols);
ab = reshape(ab,nrows*ncols,2);
nColors = 6;
% repeat the clustering 3 times to avoid local minima
[cluster_idx cluster_center] = kmeans(ab,nColors,'distance','sqEuclidean','replicates',6);
pixel_labels = reshape(cluster_idx,nrows,ncols);
%figure, imshow(pixel_labels,[]), title('image labeled by cluster index');
segmented_images = cell(1,3);
rgb_label = repmat(pixel_labels,[1 3]);
for k = 1:nColors
color = he;
color(rgb_label ~= k) = 0;
segmented_images{k} = color;
end
new_image = cellfun(@(x)reshape(x,2592*3,4608),segmented_images,'UniformOutput',false)
bayoishola20
bayoishola20 2014년 9월 22일
m-file for segmentation

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

채택된 답변

Mohammad Abouali
Mohammad Abouali 2014년 9월 19일
Well, the answer is right in front of you. BW_1 has 2592x4608=11943936 elements while new_image{1} has 7776x4608=35831808 elements
confusion requires both of them have same number of elements.
since 7776/2592=3, it is possible that you made some mistake and all 3 color bands are getting next to each other on first dimension.If your image looks black and white, it is still possible that it has three color bands; but the colors are set in such a way that it looks gray.
  댓글 수: 1
bayoishola20
bayoishola20 2014년 9월 20일
U r right, but below is the segmentation code I had used.
he= imread('C:\Users\ISHOLA\Desktop\1.jpg'); %Reading image which is not gray
cform = makecform('srgb2lab');
lab_he = applycform(he,cform);
ab = double(lab_he(:,:,2:3));
nrows = size(ab,1);
ncols = size(ab,2);
disp(nrows);
disp(ncols);
ab = reshape(ab,nrows*ncols,2);
nColors = 6;
% repeat the clustering 3 times to avoid local minima
[cluster_idx cluster_center] = kmeans(ab,nColors,'distance','sqEuclidean','replicates',6);
pixel_labels = reshape(cluster_idx,nrows,ncols);
%figure, imshow(pixel_labels,[]), title('image labeled by cluster index');
segmented_images = cell(1,3);
rgb_label = repmat(pixel_labels,[1 3]);
for k = 1:nColors
color = he;
color(rgb_label ~= k) = 0;
segmented_images{k} = color;
end
new_image = cellfun(@(x)reshape(x,2592*3,4608),segmented_images,'UniformOutput',false)

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

추가 답변 (1개)

bayoishola20
bayoishola20 2014년 9월 22일
pls this is the m-file.

카테고리

Help CenterFile Exchange에서 Convert Image Type에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by