Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid Histogram equalization algorithm gives me really bright or red image
    primarykey
    data
    text
    <p>I am doing histogram equalization on an image. I first get the RGB image and convert it to YUV. I run the histogram equalization algorithm on Y' of YUV and then convert back to RGB. Is it me, or does the image look weird? I am doing this correctly? this image is pretty bright, other images are a little red.</p> <p>Here are the before/after images:</p> <p><img src="https://adblogcat.com/wp-content/uploads/2012/07/1335218187675-150x150.jpg" alt="before"> <img src="https://adblogcat.com/wp-content/uploads/2012/07/9KB1MOGC9P-150x150.jpg" alt="after"></p> <p>The algorithm (the commented values are values that I used previously for conversion. Both yield pretty much the same results) :</p> <pre><code> public static void createContrast(Bitmap src) { int width = src.getWidth(); int height = src.getHeight(); Bitmap processedImage = Bitmap.createBitmap(width, height, src.getConfig()); int A = 0,R,G,B; int pixel; float[][] Y = new float[width][height]; float[][] U = new float[width][height]; float[][] V = new float [width][height]; int [] histogram = new int[256]; Arrays.fill(histogram, 0); int [] cdf = new int[256]; Arrays.fill(cdf, 0); float min = 257; float max = 0; for(int x = 0; x &lt; width; ++x) { for(int y = 0; y &lt; height; ++y) { pixel = src.getPixel(x, y); //Log.i("TEST","("+x+","+y+")"); A = Color.alpha(pixel); R = Color.red(pixel); G = Color.green(pixel); B = Color.blue(pixel); /*Log.i("TESTEST","R: "+R); Log.i("TESTEST","G: "+G); Log.i("TESTEST","B: "+B);*/ // convert to YUV /*Y[x][y] = 0.299f * R + 0.587f * G + 0.114f * B; U[x][y] = 0.492f * (B-Y[x][y]); V[x][y] = 0.877f * (R-Y[x][y]);*/ Y[x][y] = 0.299f * R + 0.587f * G + 0.114f * B; U[x][y] = 0.565f * (B-Y[x][y]); V[x][y] = 0.713f * (R-Y[x][y]); // create a histogram histogram[(int) Y[x][y]]+=1; // get min and max values if (Y[x][y] &lt; min){ min = Y[x][y]; } if (Y[x][y] &gt; max){ max = Y[x][y]; } } } cdf[0] = histogram[0]; for (int i=1;i&lt;=255;i++){ cdf[i] = cdf[i-1] + histogram[i]; //Log.i("TESTEST","cdf of: "+i+" = "+cdf[i]); } float minCDF = cdf[(int)min]; float denominator = width*height - minCDF; //Log.i("TEST","Histeq Histeq Histeq Histeq Histeq Histeq"); for(int x = 0; x &lt; width; ++x) { for(int y = 0; y &lt; height; ++y) { //Log.i("TEST","("+x+","+y+")"); pixel = src.getPixel(x, y); A = Color.alpha(pixel); Y[x][y] = ((cdf[ (int) Y[x][y]] - minCDF)/(denominator)) * 255; /*R = minMaxCalc(Y[x][y] + 1.140f * V[x][y]); G = minMaxCalc (Y[x][y] - 0.395f * U[x][y] - 0.581f * V[x][y]); B = minMaxCalc (Y[x][y] + 2.032f * U[x][y]);*/ R = minMaxCalc(Y[x][y] + 1.140f * V[x][y]); G = minMaxCalc (Y[x][y] - 0.344f * U[x][y] - 0.714f * V[x][y]); B = minMaxCalc (Y[x][y] + 1.77f * U[x][y]); //Log.i("TESTEST","A: "+A); /*Log.i("TESTEST","R: "+R); Log.i("TESTEST","G: "+G); Log.i("TESTEST","B: "+B);*/ processedImage.setPixel(x, y, Color.argb(A, R, G, B)); } } </code></pre> <p>}</p> <p>My next step is to graph the histograms before and after. I just want to get an opinion here.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload