Array indices must be positive integers or logical values.
2 views (last 30 days)
Show older comments
A = imread('boat.png');
A=double(A);
[row,col]=size(A);
h=zeros(1,300);
for x=1:1:row
for y=1:1:col
t=A(x,y);
% disp(t)
h(t)=h(t)+1;
end
end
subplot(2,1,1)
imshow(uint8(A))
title('Original Image')
subplot(2,1,2)
bar(h)
title('Histogram of the Image')
0 Comments
Accepted Answer
the cyclist
on 13 Apr 2021
Edited: the cyclist
on 13 Apr 2021
Your variable A is the image data.
Your variable t is the value of the image data at the (x,y) coordinate. That value of t could be equal to zero sometimes. If t==0, then this line of code
h(t)=h(t)+1;
will be equivalent to
h(0)=h(0)+1;
so you are trying to write to the "zeroth element" of the array h, which is nonexistent (and triggers the error).
6 Comments
madhan ravi
on 13 Apr 2021
Edited: madhan ravi
on 13 Apr 2021
Well, you didn't follow cyclists comments. Calculate the unique pixels sum and then use the bar function.
More Answers (0)
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!