i have problem with : Attempted to access C(0); index must be a positive integer or logical. Error in HistogramEkualisasi (line 24)

1 visualización (últimos 30 días)
"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);

Respuestas (1)

Walter Roberson
Walter Roberson el 23 de Mzo. de 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 comentarios
yusuf zain
yusuf zain el 23 de Mzo. de 2016
Editada: yusuf zain el 23 de Mzo. de 2016
thanks, but why when i tried to run this program, the image full black
Walter Roberson
Walter Roberson el 23 de Mzo. de 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.

Iniciar sesión para comentar.

Categorías

Más información sobre Image Processing Toolbox en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by