I am trying to write a function for the Gamma Correction, this is what I have so far. the problem is the intensities of the output image is either 0 or 255. what am I doing wrong?
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Reihaneh Khoshghadam
il 24 Ott 2018
Commentato: Reihaneh Khoshghadam
il 24 Ott 2018
function adjust_im= Gamma_c(im, y, c)
rows = size(im,1);
cols = size(im,2);
mat= zeros(rows,cols,class(im));
for r=1: rows
for co=1: cols
pixel = im(r,co);
p1 = double(pixel/255);
p2 = double(c*((double(p1))^y));
p3 = double(p2*255);
mat(r,co) = round(p3);
end
end
adjust_im= mat;
0 Commenti
Risposta accettata
Adam
il 24 Ott 2018
Modificato: Adam
il 24 Ott 2018
double(pixel/255)
will divide pixel by 255 then convert to a double. Assuming your image is an 8-bit integer data type this is not what you want as it will use integer division with truncation so everything apart from 255 will become 0. Use
pixel = double( im(r,co) );
or convert the whole image to double before the for loop (probably more efficient) and then you should not need all the other casts to double that you have.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Gamma Functions in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!