Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect if an image is pixelated

There is a question like this asked on SO earlier: Detecting a pixelated image in python and also on quora

I'm trying to find out whether an image uploaded by a user can be detected as 'pixelated'. By pixelated I mean images like these: In my case I don't have access to the original (non-pixelated) version.

My approach:

Not sure how effective this approach would be but if I could get RGB of each pixel in the image and then compare it to its neighbors to see if they are similar then I could detect that the image is pixelated? I can get the RGB of pixels but don't know how to go about comparing them to their neighbors.

Are there algorithms for doing something like this available already? Are there some other approaches I could take? I'm not bound to any specific language.

like image 792
birdy Avatar asked Jan 19 '13 21:01

birdy


1 Answers

Some approaches:

1) Implement canny or other edge detection and vary the edge threshold to see if the result is a grid. A grid can be detected by applying Hough line detector to the resulting edge image. See (2) below.

2) (This is really thresholding the image before edge detection; also suggest smoothing image with median filter or other noise removal filter). Scan from left to right and at each pixel color change assign either black or white to the pixel. Continue with black/white until the color changes and toggle from black to white or white to black. If pixelated you will end up with a grid like image. You can run a standard line detection on the iamge (which you can do for 1 as well) and see if the slopes of the resulting lines are vertical and parallel and if the lines are fairly equidistant. There are sample line detection algorithms on the internet (even Java implementations).

This website has references to line detection and edge detection algorithms.

EDIT: In response to question from mmgp (+1 for the challenge, I like that!), this is what I did with the sample image in the question: 1) Edge detection 2) Gray-scale 3) Hugh-transform (high threshold) Attached is the hugh-transform output. By evaluating all lines that have horizontal/vertical slope and computing distance between them, a grid pattern can be discerned. This does not automatically mean the image is pixelated (a chess board would show up as pixelated). There can be false positives.

enter image description here

like image 188
Καrτhικ Avatar answered Sep 24 '22 19:09

Καrτhικ