Results 1 to 4 of 4
  1. #1
    kabamawekesa is offline Member
    Join Date
    Nov 2014
    Posts
    1
    Rep Power
    0

    Default How to get pixel values of an image and store it into an array?

    Hey guys,
    So i wanted to try something new like find an image within an image. So for my "find" method I would like to take an image and use it to scan and compare sum of absolute differences with the bigger image. So that the smallest SAD would be the exact image that I am using to scan. What I am thinking is to put each pixel value of both images into two separate arrays and compare them via Math.abs(image1[i][j]-image2[i][j]); . My only problem is that I do not know how to put each pixel value into an array.

    Also, If I only want to compare just the green in the picture. I saw that the Pixel class has a getGreen(); method. If I want to find the SAD of the green, would Math.abs(image1.getGreen()-image2.getGreen()); work? I was planning to have 2 nested loops running through each column and row for each image and just find the SAD of the green value.


    Thanks,
    KB
    Last edited by kabamawekesa; 11-13-2014 at 12:49 AM.

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: How to get pixel values of an image and store it into an array?

    Look at the BufferedImage class. It has methods to access the pixels in an image.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: How to get pixel values of an image and store it into an array?

    Well, this appears to be more than just a 1:1 pixel comparison. You need to compare the smaller image to an equal sized sub-image of the larger image. Assume the smaller image is 100x100 pixels and the larger is 1000 x 1000 pixels. You will be comparing the smaller image to at most (901) * (901) or 811,801 sub-images of equal size. Assuming you start the comparison at (0,0) going left to right, the worst case would be that the image you are looking for is in the lower right portion of larger image. Ideally, the individual comparisons should fail quickly until you hit the correct sub-image. You may want to experiment with computing checksums on some small initial portion of each image as a prelude to actual comparison. This may speed up or slow down the overall process. Others on this forum may have more advanced techniques to offer.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  4. #4
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: How to get pixel values of an image and store it into an array?

    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. Replies: 4
    Last Post: 04-26-2012, 07:05 PM
  2. How to read the pixel values of a jpg binary image
    By carindia in forum New To Java
    Replies: 2
    Last Post: 09-17-2010, 06:19 PM
  3. problem with pixel values of an image
    By SreerajSarma in forum New To Java
    Replies: 6
    Last Post: 03-06-2010, 03:47 PM
  4. Reconstruct image from a pixel array
    By Sepho in forum New To Java
    Replies: 0
    Last Post: 08-29-2009, 12:27 AM
  5. Replies: 14
    Last Post: 04-10-2009, 08:46 AM

Posting Permissions

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