# What causes this repetition pattern in a picture? (when re-arranging its pixels by their intensity - code included)

by Nico Brenner   Last Updated August 13, 2019 23:18 PM

Just out of curiosity, I was playing with RGB coordinates and pixels of pictures. Then for some reason I decided to get all pixels of a picture, get the RGB coordinates/values of each pixel (eg. RGB(120, 30, 15)), add the coordinates together (eg. 120+30+15=165), and then sort the pixels in ascending order according to that number (the sum of the pixel's RGB coordinates/values).

So, to be able to visualize that, I "printed" the pixels to another image of the same dimensions as the original one, but with the re-arranged pixels as content. See an example below (and the Ruby code for it).

You will notice that the output picture has a very well defined pattern. I tried the same thing (re-arranging the pixels by R+G+B) with many different pictures, and there's always a similar pattern of repeating smaller versions of the same picture.

Why does that happen? What explains the pattern of the picture when the pixels are re-arranged?

Original picture:

Picture with re-arranged pixels:

``````# Ruby code
require 'rmagick'
include Magick

img = ImageList.new("images/test-image.jpg")
pixels = img.get_pixels(0,0,img.columns,img.rows)

# Sort pixels by total intensity
pixels = pixels.sort {|p| p.red + p.green + p.blue}

depth_img.store_pixels(0,0, img.columns, img.rows, pixels)
depth_img.write("images/test-image-out.jpg")
``````
Tags :