Ask Your Question

get few pixels value of grayscale image with android API

asked 2015-11-26 06:09:26 -0600

valexor89 gravatar image

Hi men, first of all sorry for my bad englisjh. I need to use a few pixels value of a grayscale image, i've searched everywhere on the web and have understood how read the pixel value but cannot resolve my problem.

In short i have a grayscale image 8UC1, under the significant code:

public boolean verify(Mat pupil, Point center, int r, int i)
{//verifica se i cerchi da disegnare coincidono esattamente con gli occhi
 //ovvero se non si discotano di tanto o anche di poco dall'iride viene escluso
    boolean flag=false;

    int x,y; 
    x = (int) (center.x); 
    y = (int) (center.y);
    int radiusx[] = {0,0};
    int radiusy[] = {0,0};
    radiusx[0] =  (x+r);
    radiusy[0] =  (y+r);
    radiusx[1] =  (x-r);
    radiusy[1] =  (y-r);
    int ep=2;

    double[] data1u,data2u,data3u,data4u; //pixel superiori
    double[] data1d,data2d,data3d,data4d; //pixel inferiori
    double diff1,diff2,diff3,diff4; //differenze tra i pixel
    //primo pixel superiore ed inferiore (orientamento 90° all'asse y1 del cerchio)
    //per alcune ragioni data1u ecc...sono nulli
    //ora usando (int)data1u[0] ottengo il valore dell'intensità
    diff1=(data1u[0]-data1d[0]); //differenza tra intensittà???[1°] e [2°] cordinate pixel
    //secondo pixel superiore ed inferiore (orientamento 180° all'asse y1 cerchio)
    //terzo pixel superiore ed inferiore (orientamento -90° all'asse y1 del cerchio)
    //essendo verso opposto, cambia il verso dell'asse positivo relativo al cerchio
    //quarto pixel superiore ed inferiore (orientamento 0° all'asse y1 del cerchio)
    //controllo: se le differenze sono valori bassi (idealmente zero) è un occhio rilevato male
    double soglia=10;
    if (diff1>soglia && diff2>soglia && diff3>soglia && diff4>soglia) //soglia un certo valore>0 non basso
    return flag;

Sorry for the cofuded code, the important is that pupil is an image not empty in grayscale and 8UC1, i'm sure, and the vectors data1u, etc... are null (viewed with debug) on diff1=(data1u[0]-data1d[0]);

Why is that? Hope in some advices. Thanks you all.

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted

answered 2015-11-26 08:15:01 -0600

valexor89 gravatar image

Sorry men, i've found the solution at this question, the problem is that when you use the method get on Mat need to switch the value x and y of cordinates, otherwise could go out of range and return null value.

So must to use as follow: Mat m = something double[] buff = m.get(Y,X); //in this form if want read only few values double value=buff[0]; //contain the pixel intensity for grayscale image //or intensity of one channel according to the model RGB or BGR

However thanks alot all of you.

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2015-11-26 06:09:26 -0600

Seen: 1,033 times

Last updated: Nov 26 '15