필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
Syed Zenith Rhyhan
Syed Zenith Rhyhan 2019년 1월 18일
댓글: Syed Zenith Rhyhan 2019년 1월 19일
% 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.
Syed Zenith Rhyhan
Syed Zenith Rhyhan 2019년 1월 19일
Thank you so much,Sir for your kind response and feedback

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

카테고리

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