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 - source

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: enter image description here

Picture with re-arranged pixels: enter image description here

# 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)

Related Questions

Choosing second lens for retro, film look

Updated October 12, 2017 00:18 AM

In camera adjustments vs editing in Lightroom

Updated May 31, 2017 19:18 PM

Do professionals all edit their pictures heavily?

Updated November 21, 2017 03:18 AM