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

1. Member
Join Date
Nov 2014
Posts
1
Rep Power
0

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. 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.

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

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

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

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

Posting Permissions

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