# Automatically shrink stretched images back to their original dimensions

We all sometimes find images on the web that are carelessly stretched to larger dimensions than original, which results in nothing but a reduction of the detail / dimensions ratio.

See Original vs Stretched below:

Source: Kaley Cuoco (Model), Esquire (Latin America)

# Stretched

Questions:

1. Given only Stretched, is there a way to automatically find the best dimensions to shrink Stretched down to which maximizes the detail / dimensions ratio?
2. Is there a generic way to define detail for all images (photos, line-art, text, etc.)?
3. Is 'stretched' the correct term or is there a more technically correct applicable?
• Is this question about Mathematica or image processing in general? – Yves Klett Mar 26 '13 at 10:43
• @YvesKlett it is about a working examplery implementation in Mathematica but general answers with hints might also be useful. – Cetin Sert Mar 26 '13 at 11:08
• There's a lot to read here, particularly about Error level Analysis, but I'm not convinced that simple resizing operations are going to show up, although I know little about it... – cormullion Mar 26 '13 at 16:51

I think the answer to your general questions is "no" there is no way that is going to allow you to figure out the original size of an image given only the upsampled (or resized) image in all cases. If you know the correct size to aim for, the mechanics in Mathematica would be simple:

 ImageResize[image , desiredSize]


So, how might you go about this? One thing is to note that if the image has been upsampled, then it has no more information in it than a smaller version. So you might try something like this:

(1) resize to a smaller version (2) resize back from the smaller version to the larger size (3) compare your new (doubly resized image) to the original (4) if there is not much difference, then you might as well keep the smaller one

Then do this for several candidate sizes until you find the best one. Of course, step (3) requires a measure of closeness of images. For this you might try ImageDistance.

• +1 Good advice. However, I fear the result of your workflow might depend more on your choice of resampling method than on internal characteristics of the image. – whuber Mar 26 '13 at 15:01
• True... but there are only about 23 methods under the Resampling help. So at least it's not infinite! – bill s Mar 26 '13 at 15:13
• Unfortunately, it doesn't matter how many methods are available: since they all lead to arbitrary results, it won't do any good to try them all. The problem stems from the inherent (potential) change of information content in the originally resized image compared to the (unknown) original image. All your procedure does is evaluate some of the statistical properties of these resampling procedures as applied to one particular input image. – whuber Mar 26 '13 at 15:20