Page 1 of 1
Mosaic an image's individual pixels?
Posted: 2019-03-01T08:15:06-07:00
by wondering
Is it possible to break an image into discreet pixels and then reassemble those pixels to form a mosaic? The intended destination mosaic has identical dimensions, if that helps.
Another way to put it is that I want to apply a color pallette to an image, but I want to use each color from the pallette only once in the destination image.
Re: Mosaic an image's individual pixels?
Posted: 2019-03-01T08:24:40-07:00
by snibgo
Yes, although I don't really know what you mean.
What version of IM, on what platform? Sample images would help us understand what you want.
If the image is fairly small, you can split it into one image per pixel, rearrange those images, and re-assemble them into a single image.
IM doesn't have great tools for rearranging images, but you can do anything you want in C, for example: sort pixels into ascending order of lightness.
Re: Mosaic an image's individual pixels?
Posted: 2019-03-01T10:50:27-07:00
by wondering
I'm using the latest version of IM on Windows, but I know MacOS too. What you're describing is exactly what I mean: Shatter an image into pixels and mosaic those pixels into a different image. I'm not sure where to start with this and I assume that writing hundreds of 1px files on disk would be painfully slow, so I hope there's a way around that.
Assemble pixels from the left to form the image on the right:
Which should result in something like this (simulated result):
Re: Mosaic an image's individual pixels?
Posted: 2019-03-01T11:32:36-07:00
by fmw42
Perhaps my bash unix script, dice, at my link below is what you want?
Re: Mosaic an image's individual pixels?
Posted: 2019-03-01T13:34:05-07:00
by wondering
No, Dice's stated purpose is "To randomly rotate each successive square-sized patch in the image." I just want to assemble pixels as if they were parts of a mosaic to form an image. I've done this for sure using IM, but it was with maybe a dozen icon-sized images. Now I'd like to do it efficiently with thousands of 1px images (aka a palette).
Re: Mosaic an image's individual pixels?
Posted: 2019-03-01T15:19:43-07:00
by snibgo
You show the red "rose:" image, and a required result with a purple rose, and a gray/purple/green image. I don't understand where that gray/purple/green image should come from, or how to use it to transform the red rose image to a purple rose image.
Re: Mosaic an image's individual pixels?
Posted: 2019-03-01T21:03:42-07:00
by wondering
The gray/purple/green image is user-provided. In this case it's just "Rose:" with its hex colours sorted alphabetically. But it could be anything else, really. The result should still be the closest possible approximation of Rose:
Re: Mosaic an image's individual pixels?
Posted: 2019-03-02T03:01:16-07:00
by snibgo
Okay, the user provides the gray/purple/green image. What processing make the final image? Does this come from both the rose and the gray/purple/green image, or just one of these?
Re: Mosaic an image's individual pixels?
Posted: 2019-03-02T10:31:15-07:00
by wondering
The processing would go like this: both the gray/purple/green image and "Rose:" are inputs.
"Rose:" is the reference image which the gray/purple/green image tries to replicate by rearranging its own pixels.
The output would be the gray/purple/green image with rearranged pixels to resemble "Rose:" as closely as possible.
The last image I provided is a simulation of the expected output.
Re: Mosaic an image's individual pixels?
Posted: 2019-03-02T10:56:35-07:00
by fmw42
Is there an algorithm or reference to an algorithm that achieves your goal?
Re: Mosaic an image's individual pixels?
Posted: 2019-03-02T11:11:08-07:00
by wondering
Not that I'm aware of. The closest thing I've seen is IM's photo mosaic feature whereby multiple images are arranged and combined to form a larger image.
Here are some examples of what I'm trying to achieve, but I want to do it with pixels instead of images:
http://www.mazaika.com/mazaika.html
Re: Mosaic an image's individual pixels?
Posted: 2019-03-02T11:23:51-07:00
by snibgo
Okay. "rose:" and the the gray/purple/green image (call this "GPG") both contain 70x46 = 3220 pixels. You want the rearrangement of GPG that most closely resembles "rose:".
There are 3220! (3220 factorial) possible arrangements. This is an enormous number, far too many to try every one.
Another possibility, as suggested in your OP:
Code: Select all
Create an empty output image 70x46 pixels.
For every pixel P1 in GPG
{
Find the closest pixel P2 in rose: for which the corresponding pixel in output is blank.
Set that pixel in output.
}
The search could be in the opposite direction, like this:
Code: Select all
Create an empty output image 70x46 pixels.
For every pixel P2 in rose: for which the corresponding pixel in output is blank
{
Find the closest pixel P1 in PGP.
Set that pixel in output.
}
I don't think IM has anything built-in that would do this.
Re: Mosaic an image's individual pixels?
Posted: 2019-03-02T11:55:36-07:00
by wondering
Seems like the second approach could work. I suppose the first step in solving this puzzle is to figure out how "closeness" between two colours is measured. Can this be expressed as a single number, or would it have to be tridimensional (RGB)?
Re: Mosaic an image's individual pixels?
Posted: 2019-03-02T12:23:53-07:00
by fmw42
the root mean squared error RMSE color difference does what I think you want.
RMSE = sqrt ( ( (r1-r2)^ + (g1-g2)^ + (b1-b2)^2 )/3 )
See
https://en.wikipedia.org/wiki/Root-mean ... _deviation
For speed, you can leave off the sqrt(), so that it becomes MSE
Zero is a perfect match.