Unable to perform assignment because the size of the left side is 1-by-512 and the size of the right side is 1-by-3. Error in A5 (line 43) empty(position,:) = [xn yn Image(xn,yn)]; PLEASE HELP ME TO SOLVE THIS ERROR

2 vues (au cours des 30 derniers jours)
clc;
close all;
%% Read Input Image - peppers_gray
Oimage=imread('peppers_gray.tif');
[M,N]=size(Oimage);
Image=Oimage(:,1:N/2);
figure(1);imshow(Image);
title('Input Image - Peppers','Color','red');
%% Selecting Seed Pixel from Input Image
figure(2),
imshow(Image, []);
[y,x,button]= ginput(1);
y = round(y);
x = round(x);
[M,N]=size(Image);
%%
%[M,N]=size(Image);
%Image=Oimage(:,1:N/2);
threshold = 13
segmentedimage = zeros(size(Image));
% 8-neighbors
nhood = [-1 -1; -1 0; -1 1; 0 -1; 0 1; 1 -1; 1 0; 1 1];
pdist = 0;
seed = Image(x,y);
reg_size = 1;
position = 0;
% some space to save co-ordinates and values of neighbors
empty = zeros(M,N);
while (pdist<threshold && reg_size<numel(Image))
for ix = 1:8
% gives the co-ordinates of the 8 neighbors
xn = x + nhood(ix,1);
yn = y + nhood(ix,2);
ins=(xn>=1)&&(yn>=1)&&(xn<=M)&&(yn<=N);
if(ins&&segmentedimage(xn,yn)==0)
position = position+1;
empty(position,:) = [xn yn Image(xn,yn)];
segmentedimage(xn,yn)=1;
end
end
% calculate the mean of the 8 connected pixel and and add the
% co-ordinates into x,y
dist = abs((empty(1:position,3)) - (seed));
[pdist, index] = min(dist);
segmentedimage(x,y)=2; reg_size=reg_size+1;
seed= (seed*reg_size + empty(index,3))/(reg_size+1);
x = empty(index,1); y = empty(index,2);
%delete the empty stuff
empty(index,:) = empty(position,:); position=position - 1;
end
segmentedimage = segmentedimage > 1;

Réponses (0)

Catégories

En savoir plus sur Images dans Help Center et File Exchange

Produits


Version

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by