1
$\begingroup$

Intro.

Previously, I've asked a question on converting rgb triple to quaternion. After that question I've managed to get unit quaternions. Since they were unit length, it was no way separating "luma and chroma", as it was initially desired. According to my feeling about it, luminance should be encoded in the either magnitude, or a real part; And color information should be encoded in the imaginary part.

Today I've decided to improve things up, taking approach, different from the first one in the link above. I think it could success, since quaternion could store not only rotation(unit quaternion), but scale as well. First things first, so I'll start with explaining my idea. Correct me if I am wrong.


Approach description and the question body.

Lets take a (3D) vector $\vec{u}$ within unit cube (representing rgb colorspace), so that its coordinates would represent red, green and blue of some pixel. Then lets take a pure white vector $\vec{v} = (1.0, 1.0, 1.0)$. The question is about finding a quaternion $\vec{q}$, satisfying equation $\vec{u} = \vec{q'}*\vec{v}*\vec{q}$ (where $*$ stands for quaternion multiplication). In simple words, $\vec{q}$ must answer the question "how to transform(rotate/scale down) white color $\vec{v}$, in order to get conceived color $\vec{u}$?"


How could You check is your answer correct?

You would require a decent computer, with working internet connection and a web browser. I use Google Chrome, and it indeed has webGL support, but you may try any other. I've prepared "testing framework" (under following link), using www.shadertoy.com service. It almost does not require programming skills (and a question itself is NOT about programming). To test your answer you may just put your formula inside c2q() function (color to quaternion converter) - syntax is pretty intuitive. Then press apply button, and you should see result: enter image description here

Image at right half(transform forth and back) must be equal to image on the left(source pixels) Thing is MUCH simplier than MATLAB. To note, numbers should always be written with decimal (eg 1.0 instead of 1). Function like dot(x,y), cross(x,y), normalize(x), length(x), sqrt(x), sin(x), and many others would just work as you expect. Program should work on any GPU, even basic ones, embedded into processors. Enjoy!


My Attempts / Hall of shame / "Lazy to type anything, just show me something fun!"

input image:

enter image description here

q = vec4(cross(u, v), dot(u, v)):

enter image description here

One of SE answers: q = vec4( cross(u, v), sqrt( dot(u, u) * dot(v, v) ) + dot(u, v) ):

enter image description here

"Don't forget to normalize q": q = normalize(vec4( cross(u, v), sqrt( dot(u, u) * dot(v, v) ) + dot(u, v) )):

enter image description here

$\endgroup$

closed as unclear what you're asking by Somos, dantopa, Eevee Trainer, Servaes, mau Apr 2 at 14:30

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • $\begingroup$ Found some useful post from Philip Nowell, describing mapping cube to sphere. This could be related to my work, and may be useful for thing I do. So I'll bookmark it here. $\endgroup$ – xakepp35 Apr 1 at 23:12
  • 1
    $\begingroup$ I'm only superficially familiar with quaternions, but could you explain what you mean by $$\vec{u} = \vec{q'}*\vec{v}*\vec{q},$$ where $\vec{u},\vec{v}\in\Bbb{R}^3$ and $\vec{q},\vec{q'}\in\Bbb{H}$? $\endgroup$ – Servaes Apr 2 at 10:15
  • $\begingroup$ @Servaes I am totally unfamiliar with quaternions, thus asked. Everything I do is on intuition. About R3,4? Just throw w away or assume it is 1.0. Same thing always happening is when you're multiplying 3D vector with 4x4 matrix. For matematitian it is "ideological catastrophe", while for 3D graphics programmers it is an everyday common practice. In my example code (check shadertoy link) it is denoted as vec4(v, 1.0) : "construct 4-elements vector from 3-elements vector and w=1.0" or q.xyz: "extract 3-elements vector from x,y and z of 4-elements vector q, and w goes nowhere" $\endgroup$ – xakepp35 Apr 2 at 10:22
  • $\begingroup$ @Servaes idea base feels correct. q.xyz = cross(u,v) and q.w = dot(u,v) seems to be a right first step. But i have to add some.. nonlinear coefficient to somewhere (more probably dot). I tried doing square root, divided by two and so on.. without success. I cannot just get brightness aligned on the both sides! $\endgroup$ – xakepp35 Apr 2 at 10:29
  • 1
    $\begingroup$ As far as I understand, the question as you have written it is "Given a vector $u\in\mathbb R^3$, how do I find two quaternions $q,q'\in\mathbb H$ such that $1+u_1i+u_2j+u_3k = q'(1+i+j+k)q$?", is that right? Are you aware that this is different from the usual application of quaternions in computer graphics, where one has a single quaternion $q$, vectors are represented as purely imaginary quaternions $u_1i+u_2j+u_3k$ without the +1, and one applies the transformation via $qv\bar q$ instead of $q'vq$? $\endgroup$ – Rahul Apr 2 at 10:53