Why do I get "Array indices must be positive integers or logical values." Image processing.
Show older comments
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");
Accepted Answer
More Answers (0)
Categories
Find more on Template Matching 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!