Crazy interpolation / imputation question

Talk about anything at all....
Post Reply
Bald Eagle
Posts: 68
Joined: Wed Apr 19, 2017 9:22 pm

Crazy interpolation / imputation question

Post by Bald Eagle »

Disclaimer / up-front apology. This has less to do with Calc specifically, and more to do with the goal, but I'm putting it here in Calc rather than General, because it seemed more suited to ask of formulators and number-crunchers.

I'm also just soliciting ideas about defining what my goal is, since all I have at this point is the impression of the goal.

It seems / is insane, but it touches on some interesting aspects of big data, databases, statistics, set theory, and probably some obscure branch of mathematics that I've yet to even hear about.
After you read this, check out the link below and maybe it will seem less insane ;) :ucrazy:
https://medium.com/@penguinpress/an-exc ... 4e708cfc3d

The final goal is this: take a digital photograph, which has the possibility of being represented with any of the 256^3 rgb values, and subtract from that universal color palette set the palette actually used to represent the image.

You are now left with the _complementary_ set of values of the color set. All of the values that _weren't_ used.
Is there a way to now implement a representation of the original image using this complementary color palette?

I'm thinking that if you had a monochrome image made from middle-gray up to white, and had to represented it with black to middle-gray, that would just be a shift. If you deleted alternate / every other value - you could use the remaining values to "fill-in" the empty values.

So in my mind, I sort of see the left-over color values as an uninflated balloon, that can somehow be stretched out to inflate and occupy the vacuum left by the original color palette.

Except this is a discontinuous balloon in a 3D rgb cube, or an HSV cylinder, or ....

I just thought this was a fun idea, and might provide an interesting topic to explore.
If there was enough development of an interpolation method, I might be able to implement it and provide a few real life examples of the results.
OpenOffice 4.1.1 on Windows 7
FJCC
Moderator
Posts: 9248
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Crazy interpolation / imputation question

Post by FJCC »

I guess I don't understand the goal at all. Imagine you have a four color map, four colors being all you need for any map. How could one usefully represent that map with the remaining ~16 million rgb colors?
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
User avatar
RoryOF
Moderator
Posts: 34586
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Crazy interpolation / imputation question

Post by RoryOF »

Why not simply invert each pixel colour? Given a pixel in a colour, what is the algorithm for assigning that to the remaining 16 million colours?
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
User avatar
keme
Volunteer
Posts: 3699
Joined: Wed Nov 28, 2007 10:27 am
Location: Egersund, Norway

Re: Crazy interpolation / imputation question

Post by keme »

RoryOF wrote:Why not simply invert each pixel colour? Given a pixel in a colour, what is the algorithm for assigning that to the remaining 16 million colours?
because, I guess, the complementary color may also be in use, and therefore disqualified.

The foundation for this undefined goal I cannot divine, though. Maybe some scheme to secure/prove intellectual rights to an image (or to circumvent such rights protection).

Enough guessing. The one with the power to enlighten is assumed to return.
Bald Eagle
Posts: 68
Joined: Wed Apr 19, 2017 9:22 pm

Re: Crazy interpolation / imputation question

Post by Bald Eagle »

Because that's not the goal.

Perhaps the answer is "you can't do that", or "there are an infinite number of ways to do that" (which is fine).
I started this off knowing, and admitting that it was a highly abstruse thing.

By complementary color I'm assuming either the inverse color, or a point diametrically opposed on the color wheel.
Neither of these things are the task I was contemplating.

If you have a color palette of M colors, you may only use N for any given digital image.
Subtract these colors actually used from the complete range of colors able to be represented by the RGB range in the palette.
This leaves you with M-N colors to work with.
The inverse of a color palette entry might exist as part of the N colors used to display another part of the image.
So that's out.
The opposing point - the complementary color - on the color wheel might also be one of the N colors.
So that's out.

So, with the remaining M-N colors - the complementary SET of colors of the whole RGB cube, how might one expand / extrapolate / interpolate those colors to now fill all of the color palette entries used to display the image.
If Nature abhors a vacuum, imagine the "real" colors being sucked out of the RGB cube with a straw - the colors in the vicinity would expand to occupy that "space" - the color palette entries of the image.

Here's the origin of this "I wonder...."
http://news.povray.org/povray.binaries. ... ay.org%3E/

I thought, perhaps in the contemplation of this - with no practical purpose in mind - some interesting theories and experiments might be conducted, and ---- it's just for fun.
There's plenty of things that didn't make much sense before someone pushed in that direction.
Instantaneous velocity. time elapsed = 0, distance traveled in 0 time = 0, velocity = 0/0 .... undefined. Until limits and calculus.
What's the square root of -1? "it doesn't exist" "we just represent it as i as a placeholder." But now imaginary numbers are used all the time for real world applications.
The Fourier transform.
Quaternions.
Octonions.
Higher dimensions. The Calabi-Yau manifold.

So I'm just looking in this weird direction, and asking, "What's in THAT direction? Right there - where the colors AREN'T?"
OpenOffice 4.1.1 on Windows 7
User avatar
keme
Volunteer
Posts: 3699
Joined: Wed Nov 28, 2007 10:27 am
Location: Egersund, Norway

Re: Crazy interpolation / imputation question

Post by keme »

Come to think of it, there is another subject that has to do with visual perception. Is it possible that you may benefit from each other's work?
viewtopic.php?f=9&t=98070&view=unread#p470527
Myndex
Posts: 19
Joined: Fri May 17, 2019 8:34 am

Re: Crazy interpolation / imputation question

Post by Myndex »

keme wrote:Come to think of it, there is another subject that has to do with visual perception. Is it possible that you may benefit from each other's work?
viewtopic.php?f=9&t=98070&view=unread#p470527
Keme brought this tread to my attention. Bald Eagle: Have you looked into ICAM or CIECAM02? They are color/appearance models, useful for the kind of color difference algorithm you're talking about.

By "palette" do you mean gamut? in 8bit sRGB there are 16.8 MILLION colors. Are you *actually* just trying to get the inverse/compliment fo the colros in the image? Or actually whatever millions of colors a particular image does not use???

Assuming you want compliments: You could also just convert to CIELAB, which is perceptually uniform and useful for applying *simple* math to perception (if that's your goal). If you goal related to light, then you want to linearize any colorspace (like sRGB) first, and possibly apply the spectral weighting.

That said: if you are talking about a typical image, there is a LOT of noise in it,so there are questions as in do you want to smooth first. And also: it's possible to have a single image with all the colors, and equally possible to have a single image with fewer than 1% of the colors.


This is sounding a bit like an X/Y problem - what is your real goal or need?

Andy
MacOS 10.6.8 thru 10.13.6 depending on which machine. OpenOffice 4.1.7 and Libre Office 6.3.2.2 on my MacBook.
Bald Eagle
Posts: 68
Joined: Wed Apr 19, 2017 9:22 pm

Re: Crazy interpolation / imputation question

Post by Bald Eagle »

Hi Andy,

I sent you a message on Sunday.
Check your User Control Panel.

I guess I've tried to explain the idea to the best of my ability in the thread, but for whatever reason, the clearer I try to be, the less I'm able to communicate. I'll mull it over a bit and try to come up with a new way to explain or illustrate what I was wondering about.

Gotta go do IRL stuff.
'Till then...
All the best :super:
OpenOffice 4.1.1 on Windows 7
Myndex
Posts: 19
Joined: Fri May 17, 2019 8:34 am

Re: Crazy interpolation / imputation question

Post by Myndex »

Bald Eagle wrote:Hi Andy,

I sent you a message on Sunday.
Check your User Control Panel.

I guess I've tried to explain the idea to the best of my ability in the thread, but for whatever reason, the clearer I try to be, the less I'm able to communicate. I'll mull it over a bit and try to come up with a new way to explain or illustrate what I was wondering about.
The one about POV ray? Ah yes, interesting.

As to THIS thread: Each pixel in a image has a single color value, BUT ALSO, a spacial value as to its location. You may have an image with 16 million pixels that only uses a subset of the 16 million available colors. But here's the thing: The color CUBE is not aware of the IMAGE spacial positions of any particular color.

It would be nothing more than a list of colors with the image colors missing, or a cube with holes in it. It would not tell you anything. You would not know If a color was used once for one pixel or 50 times for 50 pixels.

What MIGHT be interesting wold be not to see the unused colors, but to see the USED colors in their spacial place in the cube or spectral locus.

Or, I just don't get what you're trying to do...
MacOS 10.6.8 thru 10.13.6 depending on which machine. OpenOffice 4.1.7 and Libre Office 6.3.2.2 on my MacBook.
Bald Eagle
Posts: 68
Joined: Wed Apr 19, 2017 9:22 pm

Re: Crazy interpolation / imputation question

Post by Bald Eagle »

You are correct on all counts.
But now let us take that list of colors with the image colors missing, and redistribute the rgb values remaining.
Places with only a few entries missing will only shift slightly, whereas a large swath of missing color will require much more "stretching".
Keep in mind we're not interpolating.

We now have new colors occupying those positions in the list, we know what colors those positions HAD, and where those colors were in the original image. So take the new colors and replace the old colors in the proper positions.

Let's see if that helps any.
OpenOffice 4.1.1 on Windows 7
UnklDonald418
Volunteer
Posts: 1544
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: Crazy interpolation / imputation question

Post by UnklDonald418 »

I think there are two components to solving your problem.
OpenOffice Draw is a vector graphics module and provides very little support for bit mapped graphics, so reading existing RGB values and writing a different set of RGB values to a new image file would probably require something other than OpenOffice.

Once you have a list of RGB values from an image, a database could provide a way of generating a new pallet of colors.
It would probably be easiest to use a composite color value (Red * 65536 + Green * 256 + Blue) in the database.
There would be one table "ColorsAll" with all 16777216 (256^3) colors.
A second table "ColorsImg" with a list of the unique colors in the image.
A query could then calculate a relative position for each image color by dividing the composite image value by 16777216. The result should be a floating point number.
Another query using a left join between the two tables could generate a limited pallet of all the colors not found in the image (16777216 - number of unique colors in the image).
Multiplying the number of entries in the limited pallet by the floating point number representing the relative position would give you a proportionally shifted color value for each of the image colors..

Using that approach I suspect that in many cases it might be difficult to visually discern the original from the generated image.
If you want to generate a truly unique image try selecting random colors from the limited pallet.
If your problem has been solved, please edit this topic's initial post and add "[Solved]" to the beginning of the subject line
Apache OpenOffice 4.1.14 & LibreOffice 7.6.2.1 (x86_64) - Windows 10 Professional- Windows 11
Bald Eagle
Posts: 68
Joined: Wed Apr 19, 2017 9:22 pm

Re: Crazy interpolation / imputation question

Post by Bald Eagle »

Thanks UnklDonald418,

I was more interested in people's thoughts on how the algorithm would work, than what specific software package to implement.
Though OO/LO could be used, they don't HAVE to be, and I have a software tool that can read each pixel and generate a CSV file that could then be imported into Calc or Base.

With regard to your suggestion, it's unclear to me in what way the 3D color cube would be decomposed into an ordered list of database entries, which is 1D.

I mean, should I use a space-filling curve like a Hilbert curve?
https://www.youtube.com/watch?v=3s7h2MHQtxc
Invent a non-Euclidian distance function?
https://youtu.be/XFDM1ip5HdU

Plus, I can see that there may need to be concessions made with edge cases.

I've worked with Bezier patches and Bernstein polynomials, and I think there's an analogous 3D thing for voxels / DF3 files.

It certainly may be hard to discern the original from the newly generated one, but I was hoping that rather than just a random color change or well-known effect being applied, that something that very specifically filtered out the original colors, but "closed" the gap in some even way might give an interesting result never seen before. And certainly could generate some interesting discussion and Open Office experiments.

Maybe I'll have some time to fool with a bit and see what I can come up with.

Thanks again for your reply :D
OpenOffice 4.1.1 on Windows 7
UnklDonald418
Volunteer
Posts: 1544
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: Crazy interpolation / imputation question

Post by UnklDonald418 »

it's unclear to me in what way the 3D color cube would be decomposed into an ordered list of database entries, which is 1D.
It's been a decade or two since I did any graphics programming, but I suspect most graphics software store the color information as a single color number, in this case a 24 bit number.
Yes, the decimal representation 0-16777215 is a little clumsy.
If you can't get the color number directly, most programming languages have functions for doing the conversions. For instance Star Basic, a commonly used language for OO macro programming has functions:
RGB(red, green, blue)
and to go the other way
red(ColorNum)
greenColorNum)
blue(ColorNum)
Worst case it can be calculated with (red * 65536) + (green * 256 ) + blue.

That same range of numbers converted to Hexadecimal is 0-FFFFFF. Now, getting the colors is easy, the two left digits are red, the two middle digits are green and the right two digits are blue.

Your results may also depend on the format of the original image. .png files use lossless data compression. But most photographs use the .jpg format which groups similar color numbers and replaces them with one value as part of the compression process.

You might get better feedback if you posted your question on one of the graphic editor forums.
If your problem has been solved, please edit this topic's initial post and add "[Solved]" to the beginning of the subject line
Apache OpenOffice 4.1.14 & LibreOffice 7.6.2.1 (x86_64) - Windows 10 Professional- Windows 11
Myndex
Posts: 19
Joined: Fri May 17, 2019 8:34 am

Re: Crazy interpolation / imputation question

Post by Myndex »

Here is my OO implenetation for converting a 6 digit hex number sRGB (in cell A4) to individual channels.

Red4 = DEC2HEX(HEX2DEC(A4)/65536;2)
Green4 = DEC2HEX( MOD(HEX2DEC(A4);65536)/256 ;2 )
Blue4 = DEC2HEX( MOD(HEX2DEC(A4);256) ; 2)

Now for various reasons I went back to a 2 digit hex value before going forward with setting the value for each to float 0.0-1.0

It's better performance to do the above with bit-shifting if the language supports it, but I don't believe you can do that in a CALC Formula for OO.
MacOS 10.6.8 thru 10.13.6 depending on which machine. OpenOffice 4.1.7 and Libre Office 6.3.2.2 on my MacBook.
Post Reply