write a function that calculate the gamma correction for a gray image. Builds a
ID: 3808454 • Letter: W
Question
write a function that calculate the gamma correction for a gray image. Builds a table(array) of integer gamma values indexed by integer gray values for a particular exponent to avoid recomputing the gamma function for each pixel. This is called a lookup table. Given a particular gray image and gamma exponent, it creates and sets the lookup table. Do not assume that the domain, x, of the gamma function is [0,255]. You should use the domain of values in the particular image. However, you should assume the range is [0,255].
Explanation / Answer
public int[] GammaTable ( int [][] image, double exponent ) {
int min = 255,max = 0;
int row = image.length;
int col = image[0].length;
for(int i=0;i<row;i++){
for(int j=0;j<col;j++){
if(image[i][j]<min)
min = image[i][j];
if(image[i][j]>max)
max = image[i][j];
}
}
int base = max-min;
int table[] = new int[256];
for(int i=0;i<256;i++){
double val = (i/base*1.0);
double val2 = Math.pow(val, exponent);
table[i] = (int)(val2*base);
}
return table;
}
Base variable is used instead of 255 as it is mentioned in the question to populate values based on input image domain.
Formula used is ::
where base = max pixel value - min pixel value
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.