lundi 30 mars 2015

how to create a gray scale image from pixel values using java

My requirement is that, I need to convert a color image into gray scale image and obtain pixels values of gray scale image to an array and perform some encryption algorithm on that array and again using this changed pixel array, I need to convert back/create a gray scale image and display it. Here are my doubts.




  1. Using the color image I have obtained the RGB pixel values in three different arrays. As per my knowledge, gray scale pixels can be obtained by doing red+green+blue/3=gray. Here red, blue, green, gray are 2-D arrays. Is this right way to obtain gray scale pixel values?


    gray[x][y] = (r[x][y]+g[x][y]+b[x][y])/3;




  2. If this is correct, then I can easily perform algorithm on that array. The real problem arises here. How to convert back/create a gray scale image using that pixel array. An example to show how a gray scale image can be created using pixel values will be really helpful. Thank you.


    for(int x = 0;x<=height;x++) {



    for(int y = 0;y<=width;y++)
    {
    gray[x][y] = (r[x][y]+g[x][y]+b[x][y])/3;
    System.out.print(gray[x][y]+"\t");
    }
    System.out.println(" ");
    }



Aucun commentaire:

Enregistrer un commentaire