How can I solve the following error of the code segment?

1 次查看(过去 30 天)
% function main
clc;
clear all;
close all;
im = imread('3.jpg');
subplot(2,1,1),imshow(im);
subplot(2,1,2),imhist(im(:,:,1));
title('INPUT IMAGE HISTOGRAM');%figure,imhist(im(:,:,2)),title('blue');figure,imhist(im(:,:,3)),title('Green');
figure;
% j=);
I = imnoise(im,'salt & pepper',0.02);
subplot(1,2,1),imshow(I);
title('Noise adition and removal using median filter');
K = medfilt2(I);
subplot(1,2,2),imshow(K);
im = double(im);
s_img = size(im);
r = im(:,:,1);
g = im(:,:,1);
b = im(:,:,1);
% [c r] = meshgrid(1:size(i,1), 1:size(i,2));
data_vecs = [r(:) g(:) b(:)];
k= 4;
[ idx C ] = kmeansK( data_vecs, k );
% d = reshape(data_idxs, size(i,1), size(i,2));
% imagesc(d);
palette = round(C);
%Color Mapping
idx = uint8(idx);
outImg = zeros(s_img(1),s_img(2),3);
temp = reshape(idx, [s_img(1) s_img(2)]);
for i = 1 : 1 : s_img(1)
for j = 1 : 1 : s_img(2)
outImg(i,j,:) = palette(temp(i,j),:);
end
end
cluster1 = zeros(size(r));
cluster2 = zeros(size(r));
cluster3 = zeros(size(r));
cluster4 = zeros(size(r));
figure;
cluster1(find(outImg(:,:,1)==palette(1,1))) = 1;
subplot(2,2,1), imshow(cluster1);
cluster2(find(outImg(:,:,1)==palette(2,1))) = 1;
subplot(2,2,2), imshow(cluster2);
cluster3(find(outImg(:,:,1)==palette(3,1))) = 1;
subplot(2,2,3), imshow(cluster3);
cluster4(find(outImg(:,:,1)==palette(4,1))) = 1;
subplot(2,2,4), imshow(cluster4);
cc = imerode(cluster4,[1 1]);
figure,imshow(imerode(cluster4,[1 1]));
title('eroded image');
[label_im, label_count] = bwlabel(cc,8);
stats = regionprops(label_im, 'Centroid');
for i=1:label_count
area(i) = stats(i).Centroid;
end
[maxval, maxid] = max(area);
label_im(label_im ~= maxid) = 0;
label_im(label_im == maxid) = 1;
figure,imshow(label_im);
title('tumour');
% outImg = uint8(outImg);
% imtool(outImg);
code_end = 1;
ERROR:
Subscripted assignment dimension mismatch.
Error in main (line 70)
area(i) = stats(i).Centroid;
  6 个评论
Syed Zenith Rhyhan
Syed Zenith Rhyhan 2019-1-19
编辑:Syed Zenith Rhyhan 2019-1-19
Sir,I extremly sorry for the upload of wrong matlab files.Here the corrected files which I will work.Please consider the mistake and resolve the follwing error occured
Error:
Subscripted assignment dimension mismatch.
Error in main (line 70)
area(i) = stats(i).Centroid;
Walter Roberson
Walter Roberson 2019-1-19
Centroid is a vector of at least 2 elements (it will have the same number of entries as ndims applied to the image.) You cannot store a vector into a scalar location area(i)

请先登录,再进行评论。

回答(1 个)

Walter Roberson
Walter Roberson 2019-1-19
The line of code with the error does not occur in the code you attached. Your current code calls upon Area, which does not exist in the field because your current code asks regionprops for Centroid.
Centroid is a vector of at least 2 elements (it will have the same number of entries as ndims applied to the image.) You cannot store a vector into a scalar location area(i)
  3 个评论
Walter Roberson
Walter Roberson 2019-1-19
area(i) = stats(i).Centroid(1) + 1i * stats(i).Centroid(2);
You are now able to store the two pieces of information into a single location, one coded into the real() of the location and the other coded into the imag() of the location.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Convert Image Type 的更多信息

产品


版本

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by