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

1 view (last 30 days)
% 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 Comments
Syed Zenith Rhyhan
Syed Zenith Rhyhan on 19 Jan 2019
Edited: Syed Zenith Rhyhan on 19 Jan 2019
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 on 19 Jan 2019
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)

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 19 Jan 2019
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 Comments
Walter Roberson
Walter Roberson on 19 Jan 2019
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.
Syed Zenith Rhyhan
Syed Zenith Rhyhan on 19 Jan 2019
Thank you so much,Sir for your kind response and feedback

Sign in to comment.

Products


Release

R2017a

Community Treasure Hunt

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

Start Hunting!