i have problem with : Attempted to access C(0); index must be a positive integer or logical. Error in HistogramEkualisasi (line 24)
1 view (last 30 days)
Show older comments
"Error in HistogramEkualisasi (line 24)
hasil(baris, kolom) = C(Img(baris, kolom));"
Img = imread('D:\Pengolahan Citra Digital\Program MATLAB\car.jpg');
ukuran = size(Img);
jum_baris = ukuran(1);
jum_kolom = ukuran(2);
L = 256;
histog = zeros (L, 1);
for baris=1 : jum_baris
for kolom=1 : jum_kolom
histog(Img(baris, kolom)+1) = ...
histog(Img(baris, kolom)+1) +1;
end
end
alpha = (L-1) / (jum_baris * jum_kolom);
C(1) = alpha * histog(1);
for i=1 : L-1
C(i+1) = C(i) + round(alpha * histog(i+1));
end
for baris=1 : jum_baris
for kolom=1 : jum_kolom
hasil(baris, kolom) = C(Img(baris, kolom));
end
end
hasil = uint8(hasil);
imshow(hasil);
0 Comments
Answers (1)
Walter Roberson
on 23 Mar 2016
Some of your counts will be 0, so Img(baris, kolom) will sometimes be 0. You are trying to index C(Img(baris, kolom)) so you are trying to index C(0) which is not permitted.
For consistency with your earlier code you should be referring to C(Img(baris,kolom)+1)
2 Comments
Walter Roberson
on 23 Mar 2016
With the test image that I used, I do not get an all-black result.
Note that you read in a .jpg image. .jpg images are almost always RGB images, but you ignore everything except what corresponds to the red color plane. If the red color plane is empty you would not get anything useful out.
See Also
Categories
Find more on Image Processing Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!