Borrar filtros
Borrar filtros

what is the reason of this error"Field reference for multiple structure elements that is followed by more reference blocks is an error."

1 visualización (últimos 30 días)
hi.i have RGB image and want to change the value of pixels that are zero into 255 .i use the follow code but this run just once and for i=1 and j=2 return this error "Field reference for multiple structure elements that is followed by more reference blocks is an error." why? how can i solve this error?
S=size(imrgb);
num_rowgray=S(1,1);
num_colgray=S(1,2);
imr = imrgb(:,:,1);
img = imrgb(:,:,2);
imb = imrgb(:,:,3);
imcolor.r=[];
imcolor.g=[];
imcolor.b=[];
for i=1:num_rowgray
for j=1:num_colgray
imcolor(i,j).r=imr(i,j);
imcolor(i,j).g=img(i,j);
imcolor(i,j).b=imb(i,j);
if imcolor.r (i,j)==0 && imcolor.g (i,j)==0 && imcolor.b (i,j)==0
imcolor(i,j).r =255;
imcolor(i,j).g =255;
imcolor(i,j).b =255;
else
imcolor(i,j).r(i,j)=0;
imcolor(i,j).g(i,j)=0;
imcolor(i,j).b(i,j)=0;
end
j=j+1;
end
i=i+1;
end

Respuesta aceptada

Stephen23
Stephen23 el 14 de En. de 2018
There is no need to use loops and such complicated code. Logical indexing is much simpler:
X = all(imrgb==0,3);
imrgb(X(:,:,[1,1,1])) = 255;
And that is all.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by