2013-01-11

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. 

mod(29945987;255^3)=mod(29945987;16581375)=13364612

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

mod(13364612;255)=62

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?

13364612-62=13364550

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

mod(13364550;255^2)=mod(13364550;65025)=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.

13364550-34425=13330125
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.

13330125/255^2=13330125/65025=205


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”
如何縮短呢?嘛。可以將其轉換為不同的數字系統與基地大於10..最流行的是十六進制的基數為16的數字系統。在這種情況下的數目將是“1C8F083”只有7在它的符號。我的朋友試圖將它轉換為ASCII,但沒有做數學正確:D,所以他要返工。

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

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

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

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

主要規則是,我有分裂4個部分中的數字從0到255之間的值。

第一部分將是alpha通道。
alpha通道的值計算的本底值的分工,我的電話號碼和值255 ^3

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

mod(29945987;255^3)=mod(29945987;16581375)=13364612
讓我們來看看這是與255整除的數嗎?不是真的,會再次離開一些剩餘部分(第二次)。在這樣的情況下,該第二的其餘部分可以是從0到255的任何值。我們這個值是紅色通道的值

mod(13364612;255)=62
從這裡的一切糾結,可能難以遵循。
我們還有什麼可以做的餘下部分,我們有嗎?在此之前,我們得到了第二剩餘值62。減去從第一個餘數,這個值除以255 ^2?
13364612-62=13364550
在這種情況下,有第三剩餘價值34425。

mod(13364550;255^2)=mod(13364550;65025)=34425

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

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

13330125/255^2=13330125/65025=205

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

34425/255 = 135


這一切似乎很熟悉嗎?好了,這是我今天的經驗做法如何獲取值。
其實 - 類似的方法,可以使用基的-x,其中x是任意整數算法來完成。在我的情況下,它應該是255。

這是我的電話號碼的RGBA顏色
在這裡,它是在一個小的像素:






Nav komentāru:

Ierakstīt komentāru