This is going to be problematic, there are many ways to pixelate images. Even using a single method, you can have it arbitrarily rotated. In theory this rotation shouldn't affect methods like Hough, but in practice it does because you cannot have perfectly rasterized lines at arbitrary angles. My approach is simplistic, it is not going to work every time (it will probably fail most of time), but you really have to better define what you want to do. Are you going to tell the user: "hey, your image is pixelated, I don't want it" ? What you want to do is not clear, the scope is not clear too.
So here is the approach. Split your image into its color channels, your example one is a palleted GIF but that can be easily seen as a RGB image. If it is a grayscale then you mostly like have one channel, that is fine. If your image have an alpha channel, either blend it or ignore it. With this separated color channels, apply a morphological gradient in each one, binarize each one by Otsu (since it is automatic, relatively good, easily available), and combine the n binary channels into one by adding them. The morphological gradient will give a high response for strong edges (including noise), and the binarization step will keep them. Now you remove components that are too small and do a thinning to get one-pixel-wide edges. Here is what we get with your example image after these steps:
f = Import["http://www.caughtinthefire.com/wp-content/uploads/2009/03/\
fireworks-pixelate-02.gif"]
split = Binarize[ImageSubtract[Dilation[#, 1], Erosion[#, 1]]] & /@
ColorSeparate[f, "RGB"]
thin = Thinning[SelectComponents[Fold[ImageAdd, split[[1]], split[[2 ;;]]],
"Count", # > 10 &]]
Now we proceed to detect the lines in this thinned binary image. The expectation is that it will form many rectangular areas when the image is pixelated, but there is no guarantee that we can actually form these rectangular areas. Supposing we can, consider each of these areas as a connected component. Then if we perform a simply component analysis as: if the ratio between the area of its convex hull and the area of its bounding box is greater than some value, then this area is a rectangular area. If we end up with many rectangular areas, then you say your image is pixelated (but actually there is no confidence on saying such thing). Next we see the original image with the detected lines overlaid, at right we see the connected components (points that are not black) that remain after considering the analysis mentioned using a ratio > 95%. In this case, there were 542 connected components in total, which were reduced to 483. This means nearly 90% of the components are rectangular. You could also take into consideration the area of the remaining components, or combine this analysis with other ones, but I'm not doing this here.
lines = ImageLines[thin, 0.05, Method -> "RANSAC"];
Show[f, Graphics[{Thick, Blue, Line /@ lines}]] (* The left image above. *)
blank = Image[ConstantArray[255, Reverse@ImageDimensions[thin]]];
blankcc = ImagePad[Binarize[Image[Show[blank,
Graphics[{Thick, Black, Line /@ lines}]]]], 1, Black]
ccrect = SelectComponents[MorphologicalComponents[blankcc], {"BoundingBoxArea",
"ConvexArea"}, #2/#1 > 0.95 &];
Colorize[ccrect, ColorFunction -> "DarkRainbow"] (* The right image above. *)
This is your indication of "pixelated".
Here are other results considering other images. This is always a sequence of three images in this order: original, result as above without changing anything, result as above after changing the threshold for line detection.
Everything detected as rectangular. But a threshold of 0.05
for line detection is too high here, after reducing it to 0.01
we get a better division of the components.
Next we consider an image which is outside of what we expect, so we end up with very few components. There is no threshold for line detection that will give a greater amount of rectangular components, so the third image is empty (or fully black, since no component remains).
Lastly, a pixelation where the squares are rotated. The process for generating the following image might have been different than the one used in the example image, but I have no idea since I'm not the author. The right image is the result of raising the line threshold to 0.08
. The problem here is that the regions are relatively large, which I wouldn't consider for detection of pixelated images.