Results 1 to 10 of 10
  1. #1
    Seeya is offline Member
    Join Date
    Apr 2012
    Posts
    4
    Rep Power
    0

    Default 2D image feature extraction.

    Following is the program for 2d image extraction, can anybody plz explain me the first for loop??
    /*
    *<applet code=HistoGrab.class width=314 height=400>
    *<param name=img value=input.jpg>
    *</applet>*/
    import java.applet.*;
    import java.awt.*;
    import java.awt.image.*;
    public class HistoGrab extends Applet{
    Dimension d;
    Image img;
    int iw,ih;
    int pixels[];
    int w,h;
    int hist[]=new int[256];
    int max_hist=0;

    public void init()
    {
    d=getSize();
    w=d.width;
    h=d.height;

    try
    {
    img=getImage(getDocumentBase(),getParameter("img") );
    MediaTracker t=new MediaTracker(this);
    t.addImage(img,0);
    t.waitForID(0);
    iw=img.getWidth(null);
    ih=img.getHeight(null);
    pixels=new int[iw*ih];
    PixelGrabber pg=new PixelGrabber(img,0,0,iw,ih,pixels,0,iw);
    pg.grabPixels();

    }catch(InterruptedException e){};

    for(int i=0;i<iw*ih;i++)
    {
    int p=pixels[i];
    int r=0xff & (p>>16);
    int g=0xff & (p>>8);
    int b=0xff & (p);
    int y=(int)(.33 * r +.56 * g + .11 * b);
    hist[y]++;

    }
    for(int i=0;i<256;i++)
    {
    if(hist[i]>max_hist)
    max_hist=hist[i];
    }
    }

    public void update(){}

    public void paint(Graphics g){

    g.drawImage(img,0,0,null);
    int x=(w-256)/2;
    int lasty =h-h * hist[0]/max_hist;
    for(int i=0;i<256;i++,x++){
    int y=h-h * hist[i]/max_hist;
    g.setColor(new Color(i,i,i));
    g.fillRect(x,y,1,h);
    g.setColor(Color.red);
    g.drawLine(x-1,lasty,x,y);
    lasty=y;
    }
    }
    }

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default Re: 2D image feature extraction.

    BB Code List - Java Programming Forum

    can anybody plz explain me the first for loop?
    What's there to explain? Tell us what you understand so we can take it from there.
    The for Statement (The Java™ Tutorials > Learning the Java Language > Language Basics)

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default Re: 2D image feature extraction.

    Isn't that code under copyright? Do you have the author's permission to reproduce it in a public forum?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    Seeya is offline Member
    Join Date
    Apr 2012
    Posts
    4
    Rep Power
    0

    Default Re: 2D image feature extraction.

    Its not that i dnt knw how for loop works, i didn't understand what " (p>>16) " mean, i mean frm where did this 16 and 8 value come frm. and also the values .33,.56 and .11.

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default Re: 2D image feature extraction.

    Quote Originally Posted by DarrylBurke View Post
    Isn't that code under copyright? Do you have the author's permission to reproduce it in a public forum?
    Please answer this, or this thread may be removed.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default Re: 2D image feature extraction.

    Quote Originally Posted by Seeya View Post
    Its not that i dnt knw how for loop works, i didn't understand what " (p>>16) " mean, i mean frm where did this 16 and 8 value come frm. and also the values .33,.56 and .11.
    Use proper words.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  7. #7
    Seeya is offline Member
    Join Date
    Apr 2012
    Posts
    4
    Rep Power
    0

    Default Re: 2D image feature extraction.

    I have no idea about that, i saw that code in reference book, i didnt know anything about the copyright issues, so to be on safer side please remove this thread.

  8. #8
    Join Date
    May 2012
    Posts
    2
    Rep Power
    0

    Talking Re: 2D image feature extraction.

    there are 24 bits in p. each of 8 bits contain the values for red,green and blue. you are suppose to extract them.so we and them with 0000FF(1111 1111) which will set the remaining bits to 0.so for red,we are suppose to get the 1st 8 bits,so we shift the 16 bits to right.i.e if the bits are 1101 1101 1110 1110 1001 1001(before shift)it will become 0000 0000 0000 0000 1101 1101 after shift. now we and it with 0000ff so we get the 1st eight bits untouched that is the value for red.
    for next step we shift by eight for green
    nd in the last step we do it for blue.
    Note:0x notifies a hexadecimal number.i.e 0xff = FF= 00ff=0000FF.

  9. #9
    Seeya is offline Member
    Join Date
    Apr 2012
    Posts
    4
    Rep Power
    0

    Default Re: 2D image feature extraction.

    Hey thanks a lot, got my doubts cleared !!

  10. #10
    Join Date
    May 2012
    Posts
    2
    Rep Power
    0

    Default Re: 2D image feature extraction.

    Quote Originally Posted by Seeya View Post
    Hey thanks a lot, got my doubts cleared !!
    anytime :)

Similar Threads

  1. sub query extraction
    By mkarthik90 in forum Advanced Java
    Replies: 18
    Last Post: 02-13-2012, 04:00 PM
  2. green channel extraction
    By sarah49 in forum Java 2D
    Replies: 1
    Last Post: 01-27-2012, 12:14 PM
  3. Data Extraction using JAVA
    By yap_1991 in forum Advanced Java
    Replies: 1
    Last Post: 06-01-2010, 09:02 AM
  4. web extraction
    By murali in forum Networking
    Replies: 3
    Last Post: 12-13-2008, 08:10 AM
  5. Replies: 1
    Last Post: 02-04-2008, 09:26 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •