How can I detect whether a JPEG has been upscaled from a smaller original?
Asked 2/12/2015
5 views
2 answers
0
I have JPEG product photos that are typically 500ā600 pixels on the longest side. Some sellers may be enlarging older, smaller photos just to meet a minimum size requirement. Is there a reliable way to detect whether an image has been upscaled with methods like nearest-neighbor, bilinear, or bicubic interpolation? I can already catch obvious cases like added solid-color borders; Iām looking for practical ways to identify enlarged images automatically.
Originally by Photography Stack Exchange contributor. Source Ā· Licensed CC BY-SA 4.0
Photography Stack Exchange contributor
11y ago
2 Answers
14
Have a DOG sniff out blur in the photos.
If you're going to be penalizing for digitally enlarged photos, you might as well penalize for out-of-focus photos too. The blurred edges and details in both cause the same bad experience for viewers, regardless of whether it is caused by a small original or poor focus. What you want to do is detect blur, which is an absence of high spatial frequencies.
Try taking the difference between an image and a blurred copy of itself. If an image is already blurry, a 1-pixel Gaussian blur isn't going to change the image as much as if the image were sharp. So there will be more difference between a sharp image and a blurred version than there is between a blurry image and a further blurred version. In computer vision, this technique is called the "difference of Gaussians" (DOG).
- Open the image in GIMP or another layered photo editor.
- Duplicate the layer.
- Apply a Gaussian Blur with a radius of 1 pixel to this new layer.
- Change the layer mode to "Difference". The image will go black except for the edges.
- Repeat steps 1-4 for a known sharp image of similar subject matter, composition, and size.
- Compare the intensity of the edges in the two difference images. You can eyeball this or use a histogram.
I just tried this on a 400x480 pixel photo and on the same thing that had been reduced to 200x240 (50%) and then enlarged back to 400x480 (200%), and the edges in the upscaled photo were quite noticeably fainter. It won't be conclusive on a mild enlargement such as 140%, but it will catch blatant cases.
Several computer vision libraries include means to calculate difference of Gaussians on an image. So do many graphical image editors. Recent versions of GIMP, for example. include a DOG macro that automates steps 2 through 4: Filters > Edge-Detect > Difference of Gaussians, then set the radii to 1.0 and 0.0.
Related questions on other Stack Exchange sites:
- Difference of Gaussian, Laplace of Gaussian, and Mexican Hat wavelet on Signal Processing Stack Exchange
- OpenCV: Efficient Difference-of-Gaussian on Stack Overflow
DOG won't catch nearest neighbor, but you can do that by looking for a pattern of rows and columns that are identical to their immediate neighbor toward the top or left.
- Open the image.
- Duplicate the layer.
- Offset the new layer one pixel up or to the left.
- Change the layer mode to "Difference".
- Look for a pattern of blank lines.
Originally by user35791. Source Ā· Licensed CC BY-SA 4.0
user35791
11y ago
0
Generated from our catalog & community ā verify before relying on it.
There isnāt a fully reliable general-purpose way to prove a JPEG was upscaled, especially without the original file. Different resampling methods leave different traces, but image content, smooth areas, and JPEG compression can hide them, so false positives and false negatives are unavoidable.
A practical approach is to detect low detail rather than āupscalingā itself. Upscaled images often look soft because they lack high spatial frequency detail. One simple method is a blur/sharpness metric, such as comparing the image to a slightly Gaussian-blurred copy (a Difference of Gaussiansāstyle idea). If the image changes very little, it was already blurry or low-detail.
You can also compute image-complexity measures such as entropy and use them statistically across many listings to flag outliers for manual review. This wonāt prove enlargement, but it can identify suspiciously low-detail images.
In short: exact detection of nearest-neighbor/bilinear/bicubic upscaling is not dependable in general. For marketplace screening, use automated sharpness/detail metrics and then manually review flagged images.
Recommended products
UniqueBot
AI11y ago
Your Answer
Related Questions
Does downscaling an upscaled image make it look sharper?
Is rotating an image by a non-90° angle inherently lossy?
How can I filter Lightroom photos by whether theyāve been edited or cropped?
Why do my image files seem smaller after copying from the memory card, and how can I meet a 6MB requirement?
Is an iPhone 8 photo high enough resolution for an ebook and print book cover?