Why do I get "Array indices must be positive integers or logical values." Image processing.
1 view (last 30 days)
Show older comments
Tomasz Jednorowski
on 18 Nov 2020
Commented: Tomasz Jednorowski
on 19 Nov 2020
Please help me. I dont know what I doing wrong...
clear all, clc
[Iwe, map] = imread('chest-xray_2','bmp');
figure(1)
image([Iwe,map]);
title("oryginal image")
colormap(map);
Iwe=double(Iwe);
[row col deep]=size(Iwe);
IweR=Iwe(:,:,1);
IweG=Iwe(:,:,2);
IweB=Iwe(:,:,3);
Iwe_grey(:,:,1)=(IweR+IweG+IweB)/3;
Iwe_grey(:,:,2)=Iwe_grey(:,:,1);
Iwe_grey(:,:,3)=Iwe_grey(:,:,1);
Iwe_grey=Iwe_grey(:,:,1);
figure(2)
imshow(Iwe_grey);
title("monochrome image");
Iwe_grey=uint8(Iwe_grey);
%%started histogram
histogram = zeros(256,1);
for y=1:col
for x=1:row
b=Iwe_grey(x,y)+1;
histogram(b+1)=histogram(b+1)+1;
end
end
figure(3)
bar(histogram);
%%stacked histogram
cumulative(1)=histogram(1)
for z=2:256
cumulative(z)=cumulative(z-1)+histogram(z)
end
cumulative = cumulative'
%%aligned histogram
for z=1:256
hist_norm(z) = (256*cumulative(z)/cumulative(256));
end
figure(4)
plot(hist_norm);
title('aligned histogram')
for x=1:row
for y= 1:col
if(Iwe_grey(x,y)<0)
Image_out_grey(x,y)=0;
else if (Iwe_grey(y,x) > 255)
else Image_out_grey(y,x)=255*cumulative(Iwe_grey(y,x))/cumulative(255);
end;
end;
end;
end;
Image_out_grey = uint8(Image_out_grey);
figure(5)
imshow(Image_out_grey);
title("the resulting image after aligning the histogram");
0 Comments
Accepted Answer
Cris LaPierre
on 18 Nov 2020
You get that error because any time you use indexing to extract values from a variable, the index number must be integers >= 1. Somewhere in your code (you did not indicate where) you are using an invalid index.
% Good
A=[1:10];
A(3)
% Bad
A(4.3)
3 Comments
Cris LaPierre
on 18 Nov 2020
Edited: Cris LaPierre
on 18 Nov 2020
First, identify where you are indexing, and then see if the values being used are integers or not.
Here, I suspect the values in Iwe_grey are not.
More Answers (0)
See Also
Categories
Find more on Histograms in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!