How to read and extract image pixels in java and compare -


i want read rgb image , want extract image pixels. want compare each , every pixels check matching pixels in other part of image. if pixel matches original pixel , matched pixel should replace red , yellow in java.

i searched lot javaforums , image processing websites. still no perfect solution got.

give pixel extractor , pixel matcher examples proceed further.

the following getrgba method extract rgba array @ position (x, y) of image img:

private final int alpha = 24; private final int red = 16; private final int green = 8; private final int blue = 0;  public int[] getrgba(bufferedimage img, int x, int y) {        int[] color = new int[4];     color[0]=getcolor(img, x,y,red);     color[1]=getcolor(img, x,y,green);     color[2]=getcolor(img, x,y,blue);     color[3]=getcolor(img, x,y,alpha);     return color; }  public int getcolor(int x, int y, int color) {            int value=img.getrgba(x, y) >> color & 0xff;     return value; } 

pixel matcher? maybe want run loop.. considering taking (0,0) pixel original pixel, following:

    int[] originalpixel =  getrgba(img,0,0);     (int i=0;i<img.getwidth();i++)     {         (int j=0;j<img.getheight();j++)         {            int[] color1 =  getrgba(img,i,j);            if (originalpixel[0] == color1[0] && originalpixel[1] == color1[1] && originalpixel[2] == color1[2] && originalpixel[3] == color1[3]) {                img.setrgb(i, j,color.red.getrgb());            }             else {                img.setrgb(i, j,color.yellow.getrgb());            }         }     } 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -