JSBach
JSBach

Reputation: 4747

Locate a resized subimage inside an image

I am working in a project where each user has a big avatar and a thumbnail of this avatar. The avatar is 150x215 and the thumbnail is 50x50. To generate the thumbnail, the user selects a square area inside the avatar and the system crops and resizes the avatar to generate the thumbnail.

Now I need to have a 70x70 thumbnail. I cannot resize the 50x50 thumbnail because it does not look nice. My idea was to create a tool to find the thumbnail inside the avatar and, using the thumbnail location, generate the new 70x70 image. It was working well until I notice that some thumbnails are not only cropped, they are resized. When the image is resized it loses pixels what makes a pixel-by-pixel comparison impossible (so I can't detect the thumbnail location inside the avatar).

Is there any way to identify where the thumbnail is located(even though it is resized)? I am using EMGU to handle the images.

Thanks for any help

Upvotes: 0

Views: 473

Answers (1)

trumpetlicks
trumpetlicks

Reputation: 7085

[EDIT1]

Seeing your note, if you had the scaling factors applied to the original avatar, then you could create a temp thumbnail that has the same scaling factor applied, then perform a statistical equivalence check of the thumbnail against the already scaled avatar. What this would look like is finding the "difference image" of the thumbnail against the scaled avatar image for each location the thumbnail can possibly lie within the avatar. for each of these "difference images" add all of the pixel based differences into a combined single numeric difference and store that into a 2D array sized to the dimension of x and y locations the thumbnail can possibly be placed within the scaled avatar image (this will be smaller than the total avatar image size, infact it will be width = avatarWidth - thumbWidth and height = avatarHeight - thumbHeight). After you have calculated all of the single difference instances for this 2D array, simply find the min within the array and that is the top-left pixel location within the scaled avatar to use. You will of course have to take the new scaled size of the 50 x 50 thumb into account when grabbing your 70 x 70 from this calculated top-left point.

You dont (by the way) have to store this 2D array of difference values, You could simply hold a min location that is initialized with the value from the first tested location, and only update if the current location is less than the current min. This would avoid the added storage of the array.

[ORIGINAL] Once the avatar image has been resized, it has also been interpolated, which for all intensive purposes means that the original pixel information has been mathmatically changed irreversibly.

You may have better luck getting into the original thumbnailing code, and changing the thumbnail code to grab the 70 x 70 px sub-image, then create the 50 x 50 by cropping another 10 px from each side!!! This is assuming you still need both the 50 x50 and the 70 x 70 thumbnails.

Upvotes: 1

Related Questions