# G'MIC Challenge - All RGB

Create a code that creates a picture containing every 8-Bit positive (4th channel not mandatory) colors in it image. Someone with a good PC can verify if there are 256^3 colors in it. The more attractive the picture, the better.

This idea is inspired by my latest non-existent color filter. That’s how this thread got started.

Do you mean it takes a picture and forces it to have every colour rather than just generating a new image with every colour?

This means `4096x4096` image (4096x4096 = 256x256x256).
Interesting challenge, I’ve something in mind, I’ll try to prototype it soon.

So, here is my proposal : a 4096x4096 image where each pixel has a unique color (when viewed in full-size)

This image has been generated with the following script.
What it does is find a random permutation of the ‘all-colors’ image so that it minimizes a color-distance (in the YCbCr colorspace) between the permuted image and the reference image. Nothing really fancy, but it was a cool exercice anyway

``````foo :
sp colorful r. 4096,4096,1,3,5 c. 0,255 round. rgb2ycbcr.
256,256,256,3,[x,y,z] n. 0,255 round. r. {s=sqrt(whd);[s,s]},1,3,-1
eval. ">pos = round(u([w,h]-1)); col = I(x,y); I(x,y) = I(pos); I(pos) = col"
+rgb2ycbcr.
w.. 512,512,0

repeat 20
eval. ">
pos = round(u([w,h]-1));
ref1 = I(#0);     val1_rgb = I(#1);     val1 = I;
ref2 = I(#0,pos); val2_rgb = I(#1,pos); val2 = I(#2,pos);
cdist = norm(ref1 - val1)^2 + norm(ref2 - val2)^2;
pdist = norm(ref1 - val2)^2 + norm(ref2 - val1)^2;
pdist<cdist?(
I(#1) = val2_rgb;
I(#1,pos) = val1_rgb;
I(#2) = val2;
I(#2,pos) = val1;
)"
w..
on.. res.png,\$>
done
``````
5 Likes

Either works. Only rule is to have every combination of 3 positive 8I channels in one single image.

Maybe one small hint to check your 4096x4096 image has indeed all 8 bits colors :

``````check_rgb8 :
v - 256,256,256 eval.. "++i(#-1,R,G,B)"
if im!=1" || "iM!=1
v + error[0--3] "Selected image does not contain all RGB8 colors."
fi
rm. v +
``````

If `\$ gmic image.png check_rgb8` throws an error, then you’re not good

The changed image is even better. I have yet to find an actual working code (my implementation is pretty slow) that generates random colors that doesn’t exist in a image myself. Maybe that eval code could be modified to generate random colors that doesn’t exist in a image, and the result is better and faster? I was thinking on the line of color-channel count independent.

What I came up with for this challenge. Apply this to image with same size of 4096^2.

``````ww={w}
hh={h}
colormap 0
n_ww={w}
to_rgb
repeat={\$ww*\$hh}
rp=0
do
do
1,1,1,{s#-1},round(u(0,255))
+f.. i==i(#-1,0,0)
compose_channels. *
equality={iM#-1}
if \$equality rm[1,2] else a[0,1] x rm. fi
while \$equality
rp+=1
while \$rp<\$repeat

\$ww,\$hh,1,100%,i(#0,x+y*w,0)

k.
``````

All this does is to create noises of random colors that doesn’t exist in target image. Not very efficient of an algorithm, but it’s the best I could do. Hmm, maybe I could do a different algorithm using coordinate to extract non-existing value.

EDIT:
Here’s another attempt at this challenge

``````4096,4096,1,3,[x%256,y%256,floor(x/256)+(floor(y/256)*16)] k.
``````

Now, it works.

@David_Tschumperle Your check_rgb code can also be modified to find modes of rgb color as well. I just realized that. But, I’m not sure what to do about this other than to create a code which creates a pie graph of color modes.

Maybe this can help :
The following command finds a colormap of the most different colors than the one present in the input image.
Use it like this: `\$ gmic sp lena +non_colormap 16`.

``````non_colormap : check "\${1=32}>0"
e[^-1] "Compute a \$1-entry colormap of the most different colors from image\$?."
v - repeat \$! l[\$<]
64,64,64,1 eval.. "col = [R,G,B]*(w#-1-1)/255; i(#-1,col) = 1" rm..
\$1,1,1,3
repeat w # Find colormap by maximal color distance from existing points
+distance.. 1 col={[xM,yM,zM]} rm.
point.. \$col,1,1
point. \$>,0,0,1,{[\$col]/w#-2*255}
done rm..
l. +luminance. rv a y sort. +,x rows. 1 round endl # Sort colormap by increasing luminance
endl done v +
``````

I tested your command. @David_Tschumperle. I don’t understand how it all works, but it’s very much usable to find colors from maximal distance. Only issue is that there’s no option for random colors.

I did a little modification though

``````non_colormap : skip \${2=1}
check "\${1=32}>0"
e[^-1] "Compute a \$1-entry colormap of the most different colors from image\$?."
v - repeat \$! l[\$<]
64,64,64,1 eval.. "col = [R,G,B]*(w#-1-1)/255; i(#-1,col) = 1" rm..
\$1,1,1,3
repeat w # Find colormap by maximal color distance from existing points
+distance.. 1 col={[xM,yM,zM]} rm.
point.. \$col,1,1
point. \$>,0,0,1,{[\$col]/w#-2*255}
done rm..
l. if \$2 +luminance. rv a y sort. +,x rows. 1 fi round endl # Sort colormap by increasing luminance
endl done v +
``````

Added \$2 so that you can randomize the order to say for the least.

Here’s the command I tested with it.

``````1,1,1,3,round(u(0,255))
non_colormap. 14,0
k.
``````

Unlike using 14,1,1,3,round(u(0,255)), this is guaranteed to be never repeat. Mind you, 14 out of 256^3 makes the odd of you hitting the same color at least twice is about .000083446502685546875‬%.