Telephone number representation in ... one pixel..

Lets say I have a telephone number which consists of 8 numbers - "29945987"
How to shorten it? Well.. one could convert it to different numeral system with base greater than 10.. The most popular would be hex numeral system with base-16. In that case the number would be "1C8F083" with only 7 symbols in it. My friend tried to convert it as an ASCII but didn`t do it mathematecally correctly :D so he has to rework it.

Ok, but - how to get it on a ... pixel? Well, what exactly is pixel? Working with different imagery software (starting with most popular and simplest Microsoft Paint and ending with complex Adobe Photoshop, Gimp, etc) users can "paint" or do whatever they are doing with custom made colors chosen from software color palette. The color "consists" of three "base channels" representing colors - red, green and blue each having a value from 0 to 255. So each pixel has these three values. Even better, there is some "pixel formats" with additional alpha channel for opacity. 

What does it mean? It means, that in the one pixel there can be stored value, which doesn`t exceed 255^4 =4`228`250`625 - numerical information with 9 characters is safe to save in one pixel. Even better - in two pixels we can safely save information about 19 numbers or the maximum value stored in two pixels is 1.78781033478129 × 10^19 or 17878103347812900000.

The next thing is - how to encode and decode such an information?

Lets try to encode my number "29945987" in pixel step by step. Despite maybe there are another approaches how to do it, this one is mine:

The main rule is I have to split the number in 4 parts with values from 0 to 255.

The first part will be the alpha channel.
The value of alpha channel is calculated as the floor value from division of my number and the value 255^3

floor(29945987;255^3)=floor(29945987;16581375)=1 (alpha)

The second part will calculate the value for the red channel. For that we firstly need to calculate with remainder (first) of difference between given telephone number and 255^3. 


Lets see is this number dividable with 255? Not really, there will be again some remainder (second) left. In such a case this second remainder can be any value from 0 to 255. Let us this value be the value for red channel


From here everything tangles, could be hard to follow.
What else we can do with the remainders we have? Previously we got second remainder with value 62. Subtracting it from first remainder, can this value be divided with 255^2?


In this case no, there is third remainder with value 34425.


Again, we are calculating the difference between second and third remainders getting the number which can be divided with 255^2 without remainder value=0.

The division between calculated difference and 255^2 will be the value for third - green - channel. The calculated value will be lower than 255^3.


And the last - blue - fourth channel value will be the division between third remainder and 255^1

34425/255 = 135

Does this all seems familiar? Well, this is my today`s empirical approach how to get values.
Actually - the similar approach could be done using base-x algorithm where x is any integer. In my case it should be 255.

And this is the RGBA color of my telephone number
And here it is in one small pixel:

比方說我有一個由8個數字組成的電話號碼 - “ 29945987”

好了,但 - 如何獲得它在...像素?那麼,究竟是什麼是像素?使用不同的圖像軟件(最流行,最簡單的Microsoft畫圖開始和結束與複雜Adobe公司的Photoshop,GIMP等),用戶可以“畫”,或做任何他們做定制的顏色從軟件的調色板中選擇。顏色“由”三個“基本頻道”代表顏色 - 紅色,綠色和藍色的每個具有從0到255的值。因此,每個像素都有這三個值。更妙的是,有一些“額外的alpha通道,不透明的像素格式”。

這是什麼意思呢?它意味著,在一個像素中,可以存儲的值,不`噸超出255^ 4= 4`228`250`625 - 儲存在一個像素中,與9個字符的數值信息是安全的。甚至更好 - 在兩個像素,我們可以安全地保存約19個數字或存儲在兩個像素中的最大值的信息是1.78781033478129×10 ^19或17878103347812900000。

接下來的事情是 - 如何進行編碼和解碼的信息?

讓我們試著到我的電話號碼“ 29945987”編碼像素步一步。儘管也許還有另一種方法如何做到這一點,這是我的:


alpha通道的值計算的本底值的分工,我的電話號碼和值255 ^3

floor(29945987;255^3)=floor(29945987;16581375)=1 (alpha)
第二部分將計算出的紅色通道的值。為此,我們首先需要計算給定的電話號碼和255 ^3之間的差異與其餘的(第一個)。


我們還有什麼可以做的餘下部分,我們有嗎?在此之前,我們得到了第二剩餘值62。減去從第一個餘數,這個值除以255 ^2?


同樣,我們計算的第二次和第三次的餘數得到255 ^2,沒有剩餘值=0,可分為之間的差異。

計算出的差異和255之間的分工^ 2將是第三 - 綠 - 通道。計算出的值將是低於255 ^3。


最後 - 藍 - 第四通道值將是第三剩餘255 ^1之間的分工

34425/255 = 135

其實 - 類似的方法,可以使用基的-x,其中x是任意整數算法來完成。在我的情況下,它應該是255。


Nav komentāru:

Ierakstīt komentāru