sjshyu
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    1
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    An Introduction to Visual Cryptography === :::info $Visual\ cryptography$ was first introduced by Naor and Shamir at *Eurocrypt’94*. <div style="text-align: center;"> ![](https://hackmd.io/_uploads/ryUYm5KgT.png =20%x) $\quad$ ![](https://hackmd.io/_uploads/HJaLmcYl6.png =20%x) </div> <div style="text-align: center;"> Moni Naor $\qquad\qquad$ Adi Shamir ![](https://hackmd.io/_uploads/r1x59qFgT.png =80%x) </div> ::: # 1. Visual Secret Sharing * A secret imgae can be encoded into several shares, printed on $transparencies$, such that only those shares satisfying some predefined condition can reveal the secret on the $superimposition$ of the shares where the secret can be recognized by *our visual system*. * Those shares not satisfying the predefined condition *obtain no information about the secret at all*. In other word, each transparency looks a seeming random picture. * *No computation* is required in the *decoding process*. * The secret is shared among the participants who hold the shares and protected under the predefined condition, called the $access\ structures$, which designate in advance which group(s) can/cannot recover the secret. * A popular access structure, $k$ out of $n$ denoted as $(k, n)$, argues that any $k$ out of the $n$ shares can recover the secret, while any group of less than *k* ones cannot where $k$ is called the $threshold$. Table 1 gives examples of the (2, 2) access structure. <div style="text-align: center;">Table 1. Examples of the (2, 2) access structure} </div> <div align="center"> | Two encoded shares/transparencies | Superimposition | | :-------: | :--------: | | ![](https://hackmd.io/_uploads/H1A-6PKlp.png#pic_center =480x) | ![](https://hackmd.io/_uploads/Bk5shDFlp.png#pic_center =420x) | | ![](https://hackmd.io/_uploads/HJQ3kdKlp.png =88%x) | ![](https://hackmd.io/_uploads/Bk2U1_Yx6.png =70%x) | </div> * A sophisticated access structure for a participant set $P$ can be generalized as $\Gamma = (\Gamma_0, Z_M)$ with $\Gamma_0\ \cap Z_M = \varnothing$ and $\Gamma_0, Z_M \subseteq P$ where $\Gamma_0$ and *Z~M~* are the *minimum qualified set* and the *maximum forbidden set* with reagrd to $P$. Any superset of $\Gamma_0$, $Q \supseteq \Gamma_0$ ($Q \subseteq P$) is qualified to access the secret, while any subset of $Z_M$, $F \subseteq Z_M$ is forbidden ($F \subseteq P$) to acceess the secret where $Q, F \subseteq P$. That is the reason that $\Gamma_0$ ($Z_M$) is called minimum qualified (maximum forbidden) set among all subsets from $P$. * A traditional cryptographic scheme suffers from the malicious attacks or the improper management (for the encrypted data). However, secret sharing provides not only the protection among a set of participants but also the flexibility of fault tolerance. Both the degrees of $accessibility$ and $fault tolerance$ are increased. * # 2. (2, 2)-Visual Cryptographical Schemes ## 2.1 Basic idea Figure 1 illustrates the basic idea to encode a binary pixel $p$ into two shares $s_1$ and $s_2$ such that neither $s_1$ nor $s_2$ leak no information about $p$, while $s_1 + s_2$ (or $s_1\otimes s_2$) reveals $p$ in our visual system. Note that $\otimes$ denotes the superimposition operation, which is equivalence to $+$ (or) operation when operating on transparencies. ![](https://i.imgur.com/m10QZab.png =80%x) <p class="text-center"> Figure 1. Basic idea of (2, 2)-VCS for a binary pixel </p> #### Encoding Matrices The basic idea in Figure 1 can be formulated as two $encoding\ matrices\ M_0$ and $M_1$ for a white and a black pixel, respectively, as shown below. ![](https://i.imgur.com/gXRbbY1.png =90%x) Given a secret binary image $P$ and 2 participants sharing $P$, we simply encode each $p\in P$ according to the values of a *column permutation* of $M_p$ where $p$ = 0 or 1. After all pixels in $P$ are encoded, the resultant two $shares\ S_1$ and $S_2$, which are printed as *transparencies*, could be distributed to $A$ and $B$. They can only reconstruct $P$ in a visual sence when they superimpose their shares, while none of them individually could obtain any secret about $P$. We thus say that $M_0$ and $M_1$ are a set of *encoding matrices* for each white and black pixels, respectively, in (2, 2)-VCS. Since each pixel (either white or black) would be expanded into 2 pixels, we say that the $pixel\ expansion$ of this (2, 2)-VCS is 2, denoted as $m = 2$. We may encode one pixel into $1\times2$ or $2\times1$ pixels as $height \times width$ in the shares. Apparently, the relative contrast between any pair of white and black pixels in $S_1\otimes S_2$ are lower than that between those in $P$. In fact, the latter is 1, while the former is 0.5. #### Maintaining Aspect Ratio To maintain the aspct ratio of the encoded shares to be as that of $P$, we may encode each pixel into $4\ (= 2\times2)$ pixels as $height \times width$ in the shares. The encoding matrices are examplified In Figure 2. Note that the column permutations of $M_p$ involve 6 results, which are actually the elements in $C_p$ for $p$ = 0 or 1. ![](https://i.imgur.com/Jpiztad.png) <p class="text-center"> Figure 2. Encoding matrices of (2, 2)-VCS maintaining aspect ratio of <i>P</i> </p> --- ### Perfect Security Each share leaks no information about the secret. The share holder can only guess the seccret blindly (just like an outsider) in spite of holding the share. The chance for him/her to obtain the secret is no more than an outsider. Consider plaintext $P$, encoding scheme $E$ and its resultant ciphertext $C$. If $E$ encodes $x\in P$ as $y\in C$ such that $$ P(x)=P(x|y), $$ then $E$ is $perfect\ secure$. That is, the probability of event $x$ is equal to that of event $x$ given event $y$. More specifically, the probability for one to obtain $x$ given $y$ is exactly equal to that for obtaining $x$. Consequently, one cannot obtain any information about $x$ even though he/she receives $y$ in advance. (即通過觀察密文無法得到關於明文的任何資訊。) --- ## 2.2 Basic Image Processing in C++ Builder ### 2.2.1 Load BMP and Assign onto Image #### Declare Bitmap object, LoadFormFile and Assign onto Image :::spoiler Add **Panel:{Button1/2, Edit1/2, ListBox, OpenPictureDialog}, Splitter, PageControl:{TabSheet1:{Image1}, TabSheet2}** and **Image** in your Form ![](https://hackmd.io/_uploads/ryXoMvg-p.png) ::: :::spoiler Code **Button1Click** as follows: ```cpp= Graphics::TBitmap * BMP, * Y; // define global var. void __fastcall TForm1::Button1Click(TObject *Sender) { if (OpenPictureDialog1->Execute()) // 讀image { BMP = new Graphics::TBitmap(); //宣告TBitmap物件 BMP->PixelFormat = pf24bit; BMP->LoadFromFile(OpenPictureDialog1->FileName); //使用TBitmap物件讀取圖檔 Image1->Picture->Assign(BMP); //show 圖檔 to Image1 Edit1->Text = BMP->Width; //圖的寬 Edit2->Text = BMP->Height; //圖的高 String dir = ExtractFileDir(OpenPictureDialog1->FileName); String fname = OpenPictureDialog1->FileName.SubString(dir.Length()+2, OpenPictureDialog1->FileName.Length()-dir.Length()-5); ListBox1->Items->Add(fname); } } ``` ::: :::spoiler After Clicking **Button1** ![](https://hackmd.io/_uploads/rkxeOwgWp.png) Choose one BMP piture, which would be loaded onto Image1 with its width/height shown in Edit1/2 and the filename on ListBox1. ![](https://hackmd.io/_uploads/SkhxYvgbT.png =80%x) ::: ### 2.2.2 Transform a color image into an 8-color image #### Change the RGB-value of each pixel on a color image :::spoiler Add **Button2** and code **Button2Click** as follows: ```cpp= void __fastcall TForm1::Button2Click(TObject *Sender) { int i, j, rr, gg, bb; for (i=0; i<BMP->Height; i++) for (j=0; j<BMP->Width ; j++) { rr = (GetRValue(BMP->Canvas->Pixels[j][i]) <= 127) ? 0 : 255; gg = (GetGValue(BMP->Canvas->Pixels[j][i]) <= 127) ? 0 : 255; bb = (GetBValue(BMP->Canvas->Pixels[j][i]) <= 127) ? 0 : 255; BMP->Canvas->Pixels[j][i] = (TColor)RGB(rr, gg, bb); } Image1->Picture->Assign(BMP); //show 圖檔 to Image1 } ``` ::: :::spoiler After Clicking **Button2** ![](https://hackmd.io/_uploads/Sy7DcPlZ6.png =80%x) ::: :::success Note that the pointer * BMP would be overwritten after Button2 executes. We had better keep * BMP pointing to the original image and create another point, say CH, to record the newly produced 8-color image and show it in Image2. ::: :::spoiler Add **Image2** in **TabSheet2** and **Button3** in **panel1** ![](https://hackmd.io/_uploads/Bytl0PgZa.png) ::: :::spoiler The codes in **Button3** are as follows. ```cpp= void __fastcall TForm1::Button3Click(TObject *Sender) { int i, j, rr, gg, bb; Graphics::TBitmap * CH = new Graphics::TBitmap(); //宣告TBitmap物件 CH->PixelFormat = pf24bit; CH->Width = BMP->Width; //圖的寬 CH->Height = BMP->Height; for (i=0; i<CH->Height; i++) for (j=0; j<CH->Width ; j++) { rr = (GetRValue(BMP->Canvas->Pixels[j][i]) <= 127) ? 0 : 255; gg = (GetGValue(BMP->Canvas->Pixels[j][i]) <= 127) ? 0 : 255; bb = (GetBValue(BMP->Canvas->Pixels[j][i]) <= 127) ? 0 : 255; CH->Canvas->Pixels[j][i] = (TColor)RGB(rr, gg, bb); } Image2->Picture->Assign(CH); //show 圖檔 to Image1 String dir = ExtractFileDir(OpenPictureDialog1->FileName); String fname = OpenPictureDialog1->FileName.SubString(dir.Length()+2, OpenPictureDialog1->FileName.Length()-dir.Length()-5); fname += "_8-color"; ListBox1->Items->Add(fname); TabSheet2->Show(); CH->SaveToFile(fname+".bmp"); } ``` ::: ::: spoiler Load a picture and execute **Button3** ![](https://hackmd.io/_uploads/B1kDydeWp.png) ::: :::success Observe the results after the following statements execute. ```cpp! TabSheet2->Show(); CH->SaveToFile(fname+".bmp"); ::: ### 2.2.3 Transform a color image into a binary image (halftoning) ::: success A $w\times h$ color image is composed of $w\times h\ pixels$, which of which is represented by a triple $(r, g, b)$ with 24-bit where $r$ ($g$, $b$) is its red (green, blue) channel ranging in [0, 255] in a computer. A $w\times h$ grayscale image is also represented by 24-bit of the form $(gray, gray, gray)$ where $gray=(r+g+b)/3$. ::: #### 2.2.3.1 From color to grayscale :::spoiler Add **TabSheet3:{Image3}** (in **PageControl1**) and **Button4** ![](https://hackmd.io/_uploads/rkcVbdW-6.png) ::: :::spoiler Code **Button4Click** as follows: ```cpp= void __fastcall TForm1::Button4Click(TObject *Sender) { int i, j, gray, rr, gg, bb; Y = new Graphics::TBitmap(); Y->Width = BMP->Width; Y->Height = BMP->Height; for (i=0; i<BMP->Height; i++) for (j=0; j<BMP->Width ; j++) { rr = GetRValue(BMP->Canvas->Pixels[j][i]); gg = GetGValue(BMP->Canvas->Pixels[j][i]); bb = GetBValue(BMP->Canvas->Pixels[j][i]); gray = (rr+gg+bb)/3 ; Y->Canvas->Pixels[j][i] = (TColor)RGB(gray, gray, gray); } Image3->Picture->Assign(Y); String dir = ExtractFileDir(OpenPictureDialog1->FileName); String fname = OpenPictureDialog1->FileName.SubString(dir.Length()+2, OpenPictureDialog1->FileName.Length()-dir.Length()-5); fname += "_Gray"; ListBox1->Items->Add(fname); TabSheet3->Show(); CH->SaveToFile(fname+".bmp"); } ``` ::: :::spoiler Load a picture and execute **Button4** ![](https://hackmd.io/_uploads/BJEkfwZ-p.png) ::: #### 2.2.3.2 From grayscale to binary :::spoiler Add **TabSheet4:{Image4}** (in **PageControl1**) and **Button5** ![](https://hackmd.io/_uploads/rJ2kVOW-p.png) ::: :::spoiler Code Button5Click as follows: ```cpp= void __fastcall TForm1::Button5Click(TObject *Sender) { int i, j, gray, rr, gg, bb; Y = new Graphics::TBitmap(); Y->Width = BMP->Width; Y->Height = BMP->Height; for (i=0; i<BMP->Height; i++) for (j=0; j<BMP->Width ; j++) { rr = GetRValue(BMP->Canvas->Pixels[j][i]); gg = GetGValue(BMP->Canvas->Pixels[j][i]); bb = GetBValue(BMP->Canvas->Pixels[j][i]); gray = ((rr+gg+bb)/3 <= 127) ? 0 : 255; Y->Canvas->Pixels[j][i] = (TColor)RGB(gray, gray, gray); } Image4->Picture->Assign(Y); String dir = ExtractFileDir(OpenPictureDialog1->FileName); String fname = OpenPictureDialog1->FileName.SubString(dir.Length()+2, OpenPictureDialog1->FileName.Length()-dir.Length()-5); fname += "_BW"; ListBox1->Items->Add(fname); TabSheet3->Show(); CH->SaveToFile(fname+".bmp"); } ``` ::: :::spoiler Load a picture and execute **Button5** ![](https://hackmd.io/_uploads/S1GguOWZp.png) ::: #### 2.2.3.3 Halftone :::info Halftone is the reprographic technique that simulates $continuous-tone$ imagery through the use of $dots$, varying either in size or in spacing, thus generating a gradient-like effect. ::: https://en.wikipedia.org/wiki/Halftone#/media/File:Halftoning_introduction.svg :::spoiler Add **TabSheet5:{Image5}**, **TabSheet6:{Image6}** (in **PageControl1**) and **Button6/7** ![](https://hackmd.io/_uploads/HJkIbKbb6.png) ::: :::spoiler Code **Button6Click** and **Button7Click** as follows: ```cpp= void __fastcall TForm1::Button6Click(TObject *Sender) { int i, j, rr, gg, bb, gray; float error; Y = new Graphics::TBitmap(); Y->Assign(BMP); for (i=0; i<Y->Height; i++) for (j=0; j<Y->Width ; j++) { rr = GetRValue(Y->Canvas->Pixels[i][j]); gg = GetGValue(Y->Canvas->Pixels[i][j]); bb = GetBValue(Y->Canvas->Pixels[i][j]); gray = (rr+gg+bb)/3; Y->Canvas->Pixels[i][j] = (TColor)RGB(gray, gray, gray); } for (i=0; i<Y->Height; i++) for (j=0; j<Y->Width ; j++) { gray = GetRValue(Y->Canvas->Pixels[j][i]); error = gray - ((gray <= 128) ? 0 : 255); gray = (int)((float)GetRValue(Y->Canvas->Pixels[j+1][i])+ error*7/16); if (gray < 0) gray = 0; if (gray > 255) gray = 255; Y->Canvas->Pixels[j+1][i] = (TColor)RGB(gray, gray, gray); gray = (int)((float)GetRValue(Y->Canvas->Pixels[j-1][i+1])+ error*3/16); if (gray < 0) gray = 0; if (gray > 255) gray = 255; Y->Canvas->Pixels[j-1][i+1] = (TColor)RGB(gray, gray, gray); gray = (int)((float)GetRValue(Y->Canvas->Pixels[j][i+1])+ error*5/16); if (gray < 0) gray = 0; if (gray > 255) gray = 255; Y->Canvas->Pixels[j][i+1] = (TColor)RGB(gray, gray, gray); gray = (int)((float)GetRValue(Y->Canvas->Pixels[j+1][i+1])+ error/16); if (gray < 0) gray = 0; if (gray > 255) gray = 255; Y->Canvas->Pixels[j+1][i+1] = (TColor)RGB(gray, gray, gray); } Image5->Picture->Assign(Y); String dir = ExtractFileDir(OpenPictureDialog1->FileName); String fname = OpenPictureDialog1->FileName.SubString(dir.Length()+2, OpenPictureDialog1->FileName.Length()-dir.Length()-5); fname += "_HT"; ListBox1->Items->Add(fname); TabSheet3->Show(); CH->SaveToFile(fname+".bmp"); } //--------------------------------------------------------------------------- void __fastcall TForm1::Button7Click(TObject *Sender) { /* Same as lilnes 2~30 of Button6Click */ for (i=0; i<Y->Height; i++) for (j=0; j<Y->Width ; j++) { gray = (GetRValue(Y->Canvas->Pixels[j][i]) <= 128) ? 0 : 255; Y->Canvas->Pixels[j][i] = (TColor)RGB(gray, gray, gray); } Image6->Picture->Assign(Y); String dir = ExtractFileDir(OpenPictureDialog1->FileName); String fname = OpenPictureDialog1->FileName.SubString(dir.Length()+2, OpenPictureDialog1->FileName.Length()-dir.Length()-5); fname += "_BWHG"; ListBox1->Items->Add(fname); TabSheet6->Show(); Y->SaveToFile(fname+".bmp"); } ``` ::: :::spoiler Load a picture and execute **Button6/7** ![](https://hackmd.io/_uploads/SyWb-YbW6.png) ::: ---- #### 2.2.3.4 Halftoned Color The similar technic can be applied onto a color image. The resultant 8-color halftone image is popular in the printing industrail. https://upload.wikimedia.org/wikipedia/commons/a/a6/Canadian_Illustrated_News_Volume_1_Number_1_Cover.jpg https://upload.wikimedia.org/wikipedia/commons/thumb/a/ac/Julemotiv_tegnet_av_Jenny_Nystr%C3%B8m_%2824207693358%29.jpg/1280px-Julemotiv_tegnet_av_Jenny_Nystr%C3%B8m_%2824207693358%29.jpg :::spoiler Add **TabSheet8:{Image8}**, **TabSheet9:{Image9}** (in **PageControl1**) and **Button8/9** ![](https://hackmd.io/_uploads/SJy0QjWZa.png) ::: :::spoiler Code **Button8/9Click** as follow: ```cpp= void __fastcall TForm1::Button8Click(TObject *Sender) { int i, j, rr, gg, bb; float errorR, errorG, errorB; // errorA, errorX; Graphics::TBitmap * CH = new Graphics::TBitmap(); //宣告TBitmap物件 CH->Assign(BMP); for (i=0; i<CH->Height; i++) for (j=0; j<CH->Width ; j++) { rr = GetRValue(CH->Canvas->Pixels[j][i]); gg = GetGValue(CH->Canvas->Pixels[j][i]); bb = GetBValue(CH->Canvas->Pixels[j][i]); errorR = rr - ((rr <= 128) ? 0 : 255); errorG = gg - ((gg <= 128) ? 0 : 255); errorB = bb - ((bb <= 128) ? 0 : 255); rr = (int)((float)GetRValue(CH->Canvas->Pixels[j+1][i])+ errorR*7/16); gg = (int)((float)GetGValue(CH->Canvas->Pixels[j+1][i])+ errorG*7/16); bb = (int)((float)GetBValue(CH->Canvas->Pixels[j+1][i])+ errorB*7/16); if (rr < 0) rr = 0; if (rr > 255) rr = 255; if (gg < 0) gg = 0; if (gg > 255) gg = 255; if (bb < 0) bb = 0; if (bb > 255) bb = 255; CH->Canvas->Pixels[j+1][i] = (TColor)RGB(rr, gg, bb); rr = (int)((float)GetRValue(CH->Canvas->Pixels[j-1][i+1])+ errorR*3/16); gg = (int)((float)GetGValue(CH->Canvas->Pixels[j-1][i+1])+ errorG*3/16); bb = (int)((float)GetBValue(CH->Canvas->Pixels[j-1][i+1])+ errorB*3/16); if (rr < 0) rr = 0; if (rr > 255) rr = 255; if (gg < 0) gg = 0; if (gg > 255) gg = 255; if (bb < 0) bb = 0; if (bb > 255) bb = 255; CH->Canvas->Pixels[j-1][i+1] = (TColor)RGB(rr, gg, bb); rr = (int)((float)GetRValue(CH->Canvas->Pixels[j][i+1])+ errorR*5/16); gg = (int)((float)GetGValue(CH->Canvas->Pixels[j][i+1])+ errorG*5/16); bb = (int)((float)GetBValue(CH->Canvas->Pixels[j][i+1])+ errorB*5/16); if (rr < 0) rr = 0; if (rr > 255) rr = 255; if (gg < 0) gg = 0; if (gg > 255) gg = 255; if (bb < 0) bb = 0; if (bb > 255) bb = 255; CH->Canvas->Pixels[j][i+1] = (TColor)RGB(rr, gg, bb); rr = (int)((float)GetRValue(CH->Canvas->Pixels[j+1][i+1])+ errorR/16); gg = (int)((float)GetGValue(CH->Canvas->Pixels[j+1][i+1])+ errorG/16); bb = (int)((float)GetBValue(CH->Canvas->Pixels[j+1][i+1])+ errorB/16); if (rr < 0) rr = 0; if (rr > 255) rr = 255; if (gg < 0) gg = 0; if (gg > 255) gg = 255; if (bb < 0) bb = 0; if (bb > 255) bb = 255; CH->Canvas->Pixels[j+1][i+1] = (TColor)RGB(rr, gg, bb); } Image7->Picture->Assign(CH); //show 圖檔 to Image1 String dir = ExtractFileDir(OpenPictureDialog1->FileName); String fname = OpenPictureDialog1->FileName.SubString(dir.Length()+2, OpenPictureDialog1->FileName.Length()-dir.Length()-5); fname += "_HC"; ListBox1->Items->Add(fname); TabSheet7->Show(); CH->SaveToFile(fname+".bmp"); } //--------------------------------------------------------------------------- void __fastcall TForm1::Button9Click(TObject *Sender) { /* The same as lines 2~42 in Button8Click */ for (i=0; i<CH->Height; i++) for (j=0; j<CH->Width ; j++) { rr = (GetRValue(CH->Canvas->Pixels[j][i]) <= 128) ? 0 : 255; gg = (GetGValue(CH->Canvas->Pixels[j][i]) <= 128) ? 0 : 255; bb = (GetBValue(CH->Canvas->Pixels[j][i]) <= 128) ? 0 : 255; CH->Canvas->Pixels[j][i] = (TColor)RGB(rr, gg, bb); } Image8->Picture->Assign(CH); //show 圖檔 to Image1 String dir = ExtractFileDir(OpenPictureDialog1->FileName); String fname = OpenPictureDialog1->FileName.SubString(dir.Length()+2, OpenPictureDialog1->FileName.Length()-dir.Length()-5); fname += "_BWHC"; ListBox1->Items->Add(fname); TabSheet8->Show(); CH->SaveToFile(fname+".bmp"); } //--------------------------------------------------------------------------- ``` :::spoiler Load a picture and execute **Button8/9** ![](https://hackmd.io/_uploads/BJV_Rj--6.png) ::: As you can see, the black-&-white result would be much better when the color image is halftoned first as grayscale, and then binarized. ### 2.2.3 Transform a color image into a binary image (halftoning) :::spoiler Change the RGB-value of each pixel into gray-scale or binry ```javascript= void __fastcall TForm1::Button4Click(TObject *Sender) { int i, j, gray, rr, gg, bb; Y = new Graphics::TBitmap(); Y->Width = BMP->Width; Y->Height = BMP->Height; for (i=0; i<BMP->Height; i++) for (j=0; j<BMP->Width ; j++) { rr = GetRValue(BMP->Canvas->Pixels[j][i]); gg = GetGValue(BMP->Canvas->Pixels[j][i]); bb = GetBValue(BMP->Canvas->Pixels[j][i]); gray = ((rr+gg+bb)/3 <= 127) ? 0 : 255; Y->Canvas->Pixels[j][i] = (TColor)RGB(gray, gray, gray); } Image1->Picture->Assign(Y); ListBox1->Items->Add("BW_"+fname); Z[indexZ] = Y; Z[indexZ]->Width = Y->Width; Z[indexZ]->Height = Y->Height; if (++indexZ > SIZE) { Memo1->Lines->Add("Image SIZE overflow!"); TabSheet2->Show(); } } ``` ::: :::spoiler Advance pixel-RGB retrival ```javascript= // A faster way to obtain the values of RGB for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) { color = Image1->Canvas->Pixels[j][i]; b = (color&0xFF0000) >> 16; g = (color&0x00FF00) >> 8; r = (color&0x0000FF); } // Another faster way for (int i = 0; i < h; i++) { ptr1 = (Byte*)Image1->Picture->Bitmap->ScanLine[i]; for (int j = 0; j < w; j++) { b = ptr1[3*j]; g = ptr1[3*j+1]; r = ptr1[3*j+2]; } } ::: :::spoiler More about the TBitmap in Builder ```cpp TBitmap *bmp=new TBitmap(); bmp->LoadFromFile("D:\\test.jpg"); Image1->Picture->Assign(bmp); // Image1->bmp->Assign(bmp); bmp->SaveToFile("D:\\test.bmp"); bmp->Free(); String dir = ExtractFileDir(OpenPictureDialog1->FileName); String fname = OpenPictureDialog1->FileName.SubString(dir.Length()+2, OpenPictureDialog1->FileName.Length()-dir.Length()-5); ``` ::: --- ## 2.3 Implementation of (2,2)-VCS #### Encode/Decode via basic idea :::spoiler A user interface of (2, 2)-VCS may be designed as follows. ![](https://hackmd.io/_uploads/Bk_Zznr-6.png) ::: The pointer-variables, such as CH, Y, etc., used in the previous section are not easy to maintain. Let us apply an array of pointers to keep these names. :::spoiler Deinfe global variable Z as a 1-D Bitmap pointers and Initialize Z dynamically in Form1: ```javascript= Graphics::TBitmap * * Z; int indexZ = 0; //------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { // ShowMessage("I am Groot!"); // randomize(); Z = new Graphics::TBitmap * [SIZE]; for (int i = 0; i < SIZE; i++) { Z[i] = new Graphics::TBitmap(); Z[i]->PixelFormat = pf24bit; } } ``` ::: :::spoiler Refine **Button1Click** as follows: ```cpp= Graphics::TBitmap * BMP, * Y; String fname; void __fastcall TForm1::Button1Click(TObject *Sender) { if (OpenPictureDialog1->Execute()) // 讀image { BMP = new Graphics::TBitmap(); //宣告TBitmap物件 BMP->PixelFormat = pf24bit; BMP->LoadFromFile(OpenPictureDialog1->FileName); //使用TBitmap物件讀取圖檔 Image1->Picture->Assign(BMP); //show 圖檔 to Image1 Edit1->Text = BMP->Width; //圖的寬 Edit2->Text = BMP->Height; //圖的高 String dir = ExtractFileDir(OpenPictureDialog1->FileName); fname = OpenPictureDialog1->FileName.SubString(dir.Length()+2, OpenPictureDialog1->FileName.Length()-dir.Length()-5); ListBox1->Items->Add(fname); Z[indexZ] = BMP; Z[indexZ]->Width = BMP->Width; Z[indexZ]->Height = BMP->Height; if (++indexZ == SIZE) Memo1->Lines->Add("Image SIZE overflow!"); } } ``` ![](https://i.imgur.com/9ojXBUe.png) ::: :::spoiler Code AddToListBox as a seperate function to shorten the program ```javascript= # define K (TColor)RGB(0, 0, 0) # define W (TColor)RGB(255, 255, 255) void AddToListBox(Graphics::TBitmap * Y, String PName) { Form1->ListBox1->Items->Add(PName); Z[indexZ] = Y; Z[indexZ]->Width = Y->Width; Z[indexZ]->Height = Y->Height; if (++indexZ > SIZE) { Form1->Memo1->Lines->Add("Image SIZE overflow!"); Form1->TabSheet2->Show(); } } ``` ::: :::spoiler Code **Botton2/3/4Click** as follows. ```cpp= void __fastcall TForm1::Button2Click(TObject *Sender) { int i, j, rr, gg, bb; Graphics::TBitmap * CH = new Graphics::TBitmap(); //宣告TBitmap物件 CH->PixelFormat = pf24bit; CH->Width = BMP->Width; //圖的寬 CH->Height = BMP->Height; for (i=0; i<CH->Height; i++) for (j=0; j<CH->Width ; j++) { rr = (GetRValue(BMP->Canvas->Pixels[j][i]) <= 127) ? 0 : 255; gg = (GetGValue(BMP->Canvas->Pixels[j][i]) <= 127) ? 0 : 255; bb = (GetBValue(BMP->Canvas->Pixels[j][i]) <= 127) ? 0 : 255; CH->Canvas->Pixels[j][i] = (TColor)RGB(rr, gg, bb); } Image1->Picture->Assign(CH); //show 圖檔 to Image1 AddToListBox(CH, "CH_"+fname); } //--------------------------------------------------------------------------- void __fastcall TForm1::Button3Click(TObject *Sender) { int i, j, gray, rr, gg, bb; for (i=0; i<BMP->Height; i++) for (j=0; j<BMP->Width ; j++) { rr = (GetRValue(BMP->Canvas->Pixels[j][i]) <= 127) ? 0 : 255; gg = (GetGValue(BMP->Canvas->Pixels[j][i]) <= 127) ? 0 : 255; bb = (GetBValue(BMP->Canvas->Pixels[j][i]) <= 127) ? 0 : 255; gray = ((rr+gg+bb)/3 <= 127) ? 0 : 255; BMP->Canvas->Pixels[j][i] = (TColor)RGB(gray, gray, gray); } Image1->Picture->Assign(BMP); AddToListBox(BMP, "BW_"+fname); } //--------------------------------------------------------------------------- void __fastcall TForm1::Button4Click(TObject *Sender) { int i, j, gray, rr, gg, bb; A = new Graphics::TBitmap(); A->Width = BMP->Width; A->Height = BMP->Height; for (i=0; i<BMP->Height; i++) for (j=0; j<BMP->Width ; j++) { rr = GetRValue(BMP->Canvas->Pixels[j][i]); gg = GetGValue(BMP->Canvas->Pixels[j][i]); bb = GetBValue(BMP->Canvas->Pixels[j][i]); gray = ((rr+gg+bb)/3 <= 127) ? 0 : 255; A->Canvas->Pixels[j][i] = (TColor)RGB(gray, gray, gray); } Image1->Picture->Assign(A); ListBox1->Items->Add("BW_"+fname); Z[indexZ] = A; Z[indexZ]->Width = A->Width; Z[indexZ]->Height = A->Height; if (++indexZ > SIZE) { Memo1->Lines->Add("Image SIZE overflow!"); TabSheet2->Show(); } } //--------------------------------------------------------------------------- ``` ::: :::spoiler Code **ListBox1Click** as follows. ```cpp= void __fastcall TForm1::ListBox1Click(TObject *Sender) { int ind = ListBox1->ItemIndex; //判斷點到ListBox的哪一個 /* if (ind == 0) Image1->Picture->Bitmap->Assign(BMP); else if (ind == 1) Image1->Picture->Bitmap->Assign(Y); */ Image1->Picture->Bitmap->Assign(Z[ind]); } ``` ::: :::spoiler Add a Button to encode each pixel into 2 shares and decoding pixel by pixel ```javascript= void __fastcall TForm1::Button5Click(TObject *Sender) { int ind = ListBox1->ItemIndex; String prefix = ListBox1->Items->Strings[ind].SubString(1, 2); if (prefix != "BW") { Memo1->Lines->Add("Please choose a binry image!"); TabSheet2->Show(); return; } int i, j, s1=ind+1, s2=ind+2, r=ind+3; Z[s1]->Width = 2*Z[ind]->Width; Z[s2]->Width = 2*Z[ind]->Width; Z[s1]->Height = Z[ind]->Height; Z[s2]->Height = Z[ind]->Height; // ProgressBar1->Position = 0; // ProgressBar1->Max = Z[ind]->Height; for (i=0; i<Z[ind]->Height; i++) { for (j=0; j<Z[ind]->Width; j++) { if (Z[ind]->Canvas->Pixels[j][i] == W) { if (random(2)==0) { Z[s1]->Canvas->Pixels[2*j][i] = W; Z[s1]->Canvas->Pixels[2*j+1][i] = K; Z[s2]->Canvas->Pixels[2*j][i] = W; Z[s2]->Canvas->Pixels[2*j+1][i] = K; } else { Z[s1]->Canvas->Pixels[2*j][i] = K; Z[s1]->Canvas->Pixels[2*j+1][i] = W; Z[s2]->Canvas->Pixels[2*j][i] = K; Z[s2]->Canvas->Pixels[2*j+1][i] = W; } } else { if (random(2)==0) { Z[s1]->Canvas->Pixels[2*j][i] = W; Z[s1]->Canvas->Pixels[2*j+1][i] = K; Z[s2]->Canvas->Pixels[2*j][i] = K; Z[s2]->Canvas->Pixels[2*j+1][i] = W; } else { Z[s1]->Canvas->Pixels[2*j][i] = K; Z[s1]->Canvas->Pixels[2*j+1][i] = W; Z[s2]->Canvas->Pixels[2*j][i] = W; Z[s2]->Canvas->Pixels[2*j+1][i] = K; } } } // ProgressBar1->StepIt(); // >StepIt(); } String sName = ListBox1->Items->Strings[ind]; AddToListBox(Z[s1], "S1_"+sName); AddToListBox(Z[s2], "S2_"+sName); Z[r]->Width = 2*Z[ind]->Width; Z[r]->Height = Z[ind]->Height; ProgressBar1->Position = 0; ProgressBar1->Max = Z[r]->Height; for (i=0; i<Z[r]->Height; i++) { for (j=0; j<Z[r]->Width; j++) { if (Z[s1]->Canvas->Pixels[j][i] == W && Z[s2]->Canvas->Pixels[j][i] == W) Z[r]->Canvas->Pixels[j][i] = W; else Z[r]->Canvas->Pixels[j][i] = K; } ProgressBar1->StepIt(); // >StepIt(); } AddToListBox(Z[r], "S1+S2_"+sName); Image1->Picture->Assign(Z[r]); TabSheet1->Show(); } // Any better idea to shorten the program ``` | Secret | Halftone | | | -------- | -------- | -------- | | ![](https://i.imgur.com/gcpUi7q.png) | ![](https://i.imgur.com/uUt4cA4.png) | | | -------- | -------- | -------- | | S1 | S2 | S1+S2 | | ![](https://i.imgur.com/kmyXGSX.png) | ![](https://i.imgur.com/wyBsOrv.png) | ![](https://i.imgur.com/pskgdda.png) | ::: --- # 3. (3, 3)-VCS Given a secret binary image $P$ and 3 participants sharing $P$, $B_0$ and $B_1$ defined below, are a set of the encoding matrices for each white and black pixels, respectively, in (3, 3)-VCS: $$ B_0= \begin{bmatrix} 0&0&1&1\\0&1&0&1\\1&0&0&1 \end{bmatrix}, \quad B_1= \begin{bmatrix} 0&0&1&1\\0&1&0&1\\0&1&1&0 \end{bmatrix} $$ Since each pixel would be expanded into 4 pixels, we say that the pixel expansion is 4, denoted as $m = 4\ (= 2\times 2, height\times width).$ # 4. Color (2, 2)-VCS ## 4.1 Continuous tone vs. Halftone With regard to the figure below, (a) is in the form of *continuous tone*, while (b) is in that of *halftone*. ![](https://i.imgur.com/UU8eNPO.png) <p class="text-center"> Figure 3. Continuous tone vs. halftone </p> We may represent/simulate an image of continuous tone by its halftone version to simplify the subsequence encoding/decoding processes. ## 4.2 Color Models ### 4.2.1 Additive and Subtractive Color Models We summarize some informative comparison between aditive and subtrative color models in Figure 4. | ![](https://i.imgur.com/IhNM5mQ.jpg) | |:----------------------------------------:| | Figure 4. Informative comparison between aditive and subtrative color models | Since the encoded shares are printed on the *transpariences*, which would be superimposed onto each other in real applications, we adopt the subtractive color model in the encoding algorithm. ### 4.2.2 Full-color and halftone-color pixels in a computer Each pixel $p$ of an image $P$ is represented by a 24-bit word consisting of R, G and B channels with 8-bit, respectively, which form a range of $2^8\times2^8\times2^8$ colors in a personal computer. We call $p$ ($P$) a *full-color* pixel (image). We may denote $p$ as $(r, g, b)$ where $r,\ g,\ b\ (\in[0, 255])$ are color levels in R, G, B channels, respectively. Adopting the subtractive color model, we could also represent $p$ as $(c, m, y)$ where $c,\ m,\ y\ (\in [0, 255])$ are color levels in C, M, Y channels, respectively. Applying the halftone technique in each of the R, G and B channels for a full-color pixel $p$, we could simulate it by an 8($=2\times2\times2$)-color *halftone-color* pixel $h$. The set of the 8 colors that $h$ may be is {w, y, m, r, c, g, b, k} as shown below where the corresponding representations of subtractive/additive models and that in a computer are also listed. | ![](https://i.imgur.com/H1hx5kV.png) | |:---------------------------------------------------:| | Figure 5. Halftone pixels and their representations | In this way, a full-color image $P$ can be simulated by a halftone-color image $H$ by halftoning each pixel in $P$. | Full color | Halftone color | |:------------------------------------:|:------------------------------------:| | ![](https://i.imgur.com/kShxox5.png) | ![](https://i.imgur.com/YOz5g05.png) | <p class="text-center"> Figure 5. Full color and halftone color images </p> In fact, we have introduced the simplest halftone coding skill in Section 2.2.2. More sophiticated skills include *error difussion*, *classical screening*, *dithering with blue noise*, *direct binary search*, to name a few. ### 4.2.3 (2, 2)-ColorVCS: From binary to halftone-color Bridged by halftoning, the binary encoding/decoding ideas in (2, 2)-VCS for binary images (composed of 0/1 pixels) could be easily extended to deal with color halftone images (composed of (r, g, b) pixels where r, g, b$\in${0, 1} or {255, 0}. Below depicts the encoding/decoding scheme for a binary pixel $b$ and a halftone color pixel $p = (p_{\rm Y},\ p_{\rm M}, p_{\rm C})$ where $p_{\rm Y},\ p_{\rm M}, p_{\rm C}$ are the halftone values (either 0/1, or 255/0) of $p$ with respect to the Y, M, C channels, respectively. | pixel | encoding/decodig | |:---------:|:------------------------------------:| | $b$ | ![](https://i.imgur.com/kCE1144.png) | | $p_\rm C$ | ![](https://i.imgur.com/2yguAFF.png) | | $p_\rm M$ | ![](https://i.imgur.com/XQ4WSqo.png) | | $p_\rm Y$ | ![](https://i.imgur.com/NZPSBRs.png) | <p class="text-center"> Figure 6. Halftone pixels and their representations </p> Based on the aforementioned discussion, each halftone color pixel can be easily (1) decomposed into the C, M, Y channels, i.e. $p = (p_{\rm C},\ p_{\rm M}, p_{\rm Y})$, (2) encoded each channel value $p_x$ as a binary pixel into $s_{x1}$ and $s_{x2}$ where $x\in${C, M, Y} (3) collapsed the $s_{\rm C}$$_i$, $s_{\rm M}$$_i$, $s_{\rm Y}$$_i$ channel-values back to share pixel $s_i$ for $i\in${1, 2}. Then, $s_1$ and $s_2$ becomes the two shares of $p$, both of which give no information about $p$; whereas, $s_1\otimes s_2$ reveals $p$ to our eyes where $\otimes$ is the superimposition operation. Figure 6 shows the combination of color *decomposition* and *reconstrution* for encoding/decoding a halftone (namely, blue) pixel in a (2, 2)-ColorVCS. | ![](https://i.imgur.com/b5ma2PT.png) | |:---------------------------------------------------:| | Figure 7. Color decomposition and reconstrution for encoding/decoding a halftone (blue) pixel | We give an implementation result of (2, 2)-CVCS with a pixel expansion of 2 in Figure 7. |![](https://i.imgur.com/XBbJtI4.png) | ![](https://i.imgur.com/7GNBpw1.png) | ![](https://i.imgur.com/bYGtSZ9.png) | |--|--|--| (a) C, M, Y halftone channels of $P$: $P\rm {_C}$, $P\rm {_M}$ and $P\rm {_Y}$ | ![](https://i.imgur.com/VSFkLIt.png) | ![](https://i.imgur.com/pGcDa8X.png) | | -- | -- | | ![](https://i.imgur.com/UaxmsXB.png) | ![](https://i.imgur.com/q7QKcIR.png) | |![](https://i.imgur.com/wsoACmf.png) | ![](https://i.imgur.com/5WaxyIn.png) | (b) C, M, Y shares: $S\rm_{C1}$, $S\rm_{C2}$, $S\rm_{M1}$, $S\rm_{M2}$ and $S\rm_{Y1}$, $S\rm_{Y2}$ | ![](https://i.imgur.com/oUNSPr0.png) | ![](https://i.imgur.com/IdGHg3F.png) | | - | - | (c\) encoded shares: $S_1$ and $S_2$, which are the compositions of $(S\rm_{C1}$, $S\rm_{M1}$, $S\rm_{Y1})$ and $(S\rm_{C2}$, $S\rm_{M2}$, $S\rm_{Y2})$ | ![](https://i.imgur.com/vsu7BMJ.png) | ![](https://i.imgur.com/QXfmR2G.png) | | ------------------------------------ | ------------------------------------ | (d) Secret image $P$ and the superimposed result of $S_1\otimes S_2$ <p class="text-center"> Figure 8. An implementation result of (2, 2)-ColerVCS </p> Consider a halftone pixel $p = (p_{\rm C},\ p_{\rm M}, p_{\rm Y})_{CMY}$ with its additive color ($r,\ g,\ b)_{RGB}$. It is not hard to see from Figure 5 that $p_{\rm C}$ ($p_{\rm M}$, $p_{\rm Y}$) = 1 if and only if $r$ ($g$, $b$, respectively) = 0. In other words, \begin{align} p_{\rm C} = \bar r, \ p_{\rm M} = \bar g,\ p_{\rm Y} = \bar b\ \tag{1} \end{align} or \begin{align} r = \bar {p_{\rm C}}, \ g = \bar {p_{\rm M}},\ b = \bar {p_{\rm Y}}\ \tag{2} \end{align} where $\bar x=1\ (0)$, if $x=0\ (1)$ for $x\in \{r,\ g,\ b\}$. For instance, when halftone pixel **m** = (0, 1, 0)$_{CMY}$ would be displayed on the computer screen, which follows the additive model to show colors, we simply set it as (1, 0, 1)$_{RGB}$ or (255, 0, 255)$_{RGB}$ in a computer porgram (or **g** = (1, 0, 1)$_{CMY}$ by setting it as (0, 1, 0)$_{RGB}$ or (0, 255, 0)$_{RGB}$). In short, \begin{align} (p_{\rm C},\ p_{\rm M},\ p_{\rm Y})_{CMY} = (\bar {p_{\rm R}},\ \bar {p_{\rm G}},\ \bar {p_{\rm B}})_{RGB} \tag{3} \end{align} or \begin{align} (r,\ g,\ b)_{RGB} = (\bar r,\ \bar g,\ \bar b)_{CMY}. \tag{4} \end{align} In the computer implementation, we use the form of $(r, g, b)_{RGB}$ to represent all 8 halftone colors. Specifically, we adopt (0, 255, 255)$_{RGB}$ to represent color C $=(1, 0, 0)_{CMY}$, while (255, 255, 255)$_{RGB}$ to represent color W $=(0, 0, 0)_{CMY}$. That is, if $c=1\ (0)$ in $CMY$ mode, $r=0$ (255) in $RGB$ mode. Thus, regarding any halftone color $(r, g, b)_{RGB}$, its corresponding color in $C$-channel is ($r$, 255, 255). With the same reasoning, its corresponding colors in $C/M$-channels are ($r$, 255, 255)/(255, $g$, 255), respectively. The following table summarized the aforementioned discussion. <\table> colspan = 3 |halftone pixel ||$(r, g, b)$ || |:----------------:|:---------------:|:---------------:|:---------------:| | Channel | $C$ | $M$ | $Y$ | | color in$_{RGB}$ | ($r$, 255, 255) | (255, $g$, 255) | (255, 255, $b$) | ### 4.2.4 Naive implementation of (2, 2)-ColorVCS The following procudure were coded quite naively for your reference. Note that "copy/paste" is NOT a good way to learn the lessons. Further, you had better simplify the codes as far as you could. ::: spoiler Naive implementation ```cpp= # define SIZE 30 # define K (TColor) RGB(0, 0, 0) # define W (TColor) RGB(255, 255, 255) # define R (TColor) RGB(255, 0, 0) # define G (TColor) RGB(0, 255, 0) # define B (TColor) RGB(0, 0, 255) # define C (TColor) RGB(0, 255, 255) # define M (TColor) RGB(255, 0, 255) # define Y (TColor) RGB(255, 255, 0) // ------------- void __fastcall TForm1::Button5Click(TObject *Sender) { int ind = ListBox1->ItemIndex; String prefix = ListBox1->Items->Strings[ind].SubString(1, 2); if (prefix != "CH") { Memo1->Lines->Add("Please choose a binry image!"); TabSheet2->Show(); return; } int i, j, c=ind+1, m=ind+2, y=ind+3, rr, gg, bb; Z[c]->Width = Z[ind]->Width; Z[m]->Width = Z[ind]->Width; Z[y]->Width = Z[ind]->Width; Z[c]->Height = Z[ind]->Height; Z[m]->Height = Z[ind]->Height; Z[y]->Height = Z[ind]->Height; ProgressBar1->Position = 0; ProgressBar1->Step = 1; // ProgressBar1->Max = Z[ind]->Height; ProgressBar1->Max = 4; //13*Z[ind]->Height; for (i=0; i<Z[ind]->Height; i++) { for (j=0; j<Z[ind]->Width; j++) { rr = GetRValue(Z[ind]->Canvas->Pixels[j][i]); gg = GetGValue(Z[ind]->Canvas->Pixels[j][i]); bb = GetBValue(Z[ind]->Canvas->Pixels[j][i]); Z[c]->Canvas->Pixels[j][i] = TColor RGB(rr, 255, 255); Z[m]->Canvas->Pixels[j][i] = TColor RGB(255, gg, 255); Z[y]->Canvas->Pixels[j][i] = TColor RGB(255, 255, bb); } } String sName = ListBox1->Items->Strings[ind]; AddToListBox(Z[c], "C_"+sName); AddToListBox(Z[m], "M_"+sName); AddToListBox(Z[y], "Y_"+sName); ProgressBar1->StepIt(); int c1=ind+4, c2=ind+5, m1=ind+6, m2=ind+7, y1=ind+8, y2=ind+9; Z[c1]->Width = 2*Z[ind]->Width; Z[m1]->Width = 2*Z[ind]->Width; Z[y1]->Width = 2*Z[ind]->Width; Z[c2]->Width = 2*Z[ind]->Width; Z[m2]->Width = 2*Z[ind]->Width; Z[y2]->Width = 2*Z[ind]->Width; Z[c1]->Height = Z[ind]->Height; Z[m1]->Height = Z[ind]->Height; Z[y1]->Height = Z[ind]->Height; Z[c2]->Height = Z[ind]->Height; Z[m2]->Height = Z[ind]->Height; Z[y2]->Height = Z[ind]->Height; for (i=0; i<Z[ind]->Height; i++) { for (j=0; j<Z[ind]->Width; j++) { rr = GetRValue(Z[c]->Canvas->Pixels[j][i]); gg = GetGValue(Z[m]->Canvas->Pixels[j][i]); bb = GetBValue(Z[y]->Canvas->Pixels[j][i]); if (rr == 0) // C is 1 { if (random(2)==0) { Z[c1]->Canvas->Pixels[2*j][i] = W; Z[c1]->Canvas->Pixels[2*j+1][i] = C; Z[c2]->Canvas->Pixels[2*j][i] = C; Z[c2]->Canvas->Pixels[2*j+1][i] = W; } else { Z[c1]->Canvas->Pixels[2*j][i] = C; Z[c1]->Canvas->Pixels[2*j+1][i] = W; Z[c2]->Canvas->Pixels[2*j][i] = W; Z[c2]->Canvas->Pixels[2*j+1][i] = C; } } else // C is 0 { if (random(2)==0) { Z[c1]->Canvas->Pixels[2*j][i] = W; Z[c1]->Canvas->Pixels[2*j+1][i] = C; Z[c2]->Canvas->Pixels[2*j][i] = W; Z[c2]->Canvas->Pixels[2*j+1][i] = C; } else { Z[c1]->Canvas->Pixels[2*j][i] =C; Z[c1]->Canvas->Pixels[2*j+1][i] = W; Z[c2]->Canvas->Pixels[2*j][i] = C; Z[c2]->Canvas->Pixels[2*j+1][i] = W; } } if (gg == 0) // M is 1 { if (random(2)==0) { Z[m1]->Canvas->Pixels[2*j][i] = W; Z[m1]->Canvas->Pixels[2*j+1][i] = M; Z[m2]->Canvas->Pixels[2*j][i] = M; Z[m2]->Canvas->Pixels[2*j+1][i] = W; } else { Z[m1]->Canvas->Pixels[2*j][i] = M; Z[m1]->Canvas->Pixels[2*j+1][i] = W; Z[m2]->Canvas->Pixels[2*j][i] = W; Z[m2]->Canvas->Pixels[2*j+1][i] = M; } } else // M is 0 { if (random(2)==0) { Z[m1]->Canvas->Pixels[2*j][i] = W; Z[m1]->Canvas->Pixels[2*j+1][i] = M; Z[m2]->Canvas->Pixels[2*j][i] = W; Z[m2]->Canvas->Pixels[2*j+1][i] = M; } else { Z[m1]->Canvas->Pixels[2*j][i] = M; Z[m1]->Canvas->Pixels[2*j+1][i] = W; Z[m2]->Canvas->Pixels[2*j][i] = M; Z[m2]->Canvas->Pixels[2*j+1][i] = W; } } if (bb == 0) // Y is 1 { if (random(2)==0) { Z[y1]->Canvas->Pixels[2*j][i] = W; Z[y1]->Canvas->Pixels[2*j+1][i] = Y; Z[y2]->Canvas->Pixels[2*j][i] = Y; Z[y2]->Canvas->Pixels[2*j+1][i] = W; } else { Z[y1]->Canvas->Pixels[2*j][i] = Y; Z[y1]->Canvas->Pixels[2*j+1][i] = W; Z[y2]->Canvas->Pixels[2*j][i] = W; Z[y2]->Canvas->Pixels[2*j+1][i] = Y; } } else // Y is 0 { if (random(2)==0) { Z[y1]->Canvas->Pixels[2*j][i] = W; Z[y1]->Canvas->Pixels[2*j+1][i] = Y; Z[y2]->Canvas->Pixels[2*j][i] = W; Z[y2]->Canvas->Pixels[2*j+1][i] = Y; } else { Z[y1]->Canvas->Pixels[2*j][i] = Y; Z[y1]->Canvas->Pixels[2*j+1][i] = W; Z[y2]->Canvas->Pixels[2*j][i] = Y; Z[y2]->Canvas->Pixels[2*j+1][i] = W; } } } } sName = ListBox1->Items->Strings[ind]; AddToListBox(Z[c1], "SC1_"+sName); AddToListBox(Z[c2], "SC2_"+sName); AddToListBox(Z[m1], "SM1_"+sName); AddToListBox(Z[m2], "SM2_"+sName); AddToListBox(Z[y1], "SY1_"+sName); AddToListBox(Z[y2], "SY2_"+sName); ProgressBar1->StepIt(); int s1 = ind+10, s2 = ind+11, r = ind+12; Z[s1]->Width = 2*Z[ind]->Width; Z[s2]->Width = 2*Z[ind]->Width; Z[r]->Width = 2*Z[ind]->Width; Z[s1]->Height = Z[ind]->Height; Z[s2]->Height = Z[ind]->Height; Z[r]->Height = Z[ind]->Height; for (i=0; i<Z[c1]->Height; i++) { for (j=0; j<Z[c1]->Width; j++) { rr = GetRValue(Z[c1]->Canvas->Pixels[j][i]); gg = GetGValue(Z[m1]->Canvas->Pixels[j][i]); bb = GetBValue(Z[y1]->Canvas->Pixels[j][i]); Z[s1]->Canvas->Pixels[j][i] = TColor RGB(rr, gg, bb); rr = GetRValue(Z[c2]->Canvas->Pixels[j][i]); gg = GetGValue(Z[m2]->Canvas->Pixels[j][i]); bb = GetBValue(Z[y2]->Canvas->Pixels[j][i]); Z[s2]->Canvas->Pixels[j][i] = TColor RGB(rr, gg, bb); } } AddToListBox(Z[s1], "S1_"+sName); AddToListBox(Z[s2], "S2_"+sName); ProgressBar1->StepIt(); int r2, g2, b2; for (i=0; i<Z[c1]->Height; i++) { for (j=0; j<Z[c1]->Width; j++) { rr = GetRValue(Z[s1]->Canvas->Pixels[j][i]); gg = GetGValue(Z[s1]->Canvas->Pixels[j][i]); bb = GetBValue(Z[s1]->Canvas->Pixels[j][i]); r2 = GetRValue(Z[s2]->Canvas->Pixels[j][i]); g2 = GetGValue(Z[s2]->Canvas->Pixels[j][i]); b2 = GetBValue(Z[s2]->Canvas->Pixels[j][i]); Z[r]->Canvas->Pixels[j][i] = TColor RGB(rr & r2, gg & g2, bb & b2); } } AddToListBox(Z[r], "S1+S2_"+sName); ProgressBar1->StepIt(); TabSheet1->Show(); } ``` ::: ### You might need some additional funtions: ::: spoiler Reset the limited BMP space ```cpp= void __fastcall TForm1::Button7Click(TObject *Sender) { ListBox1->Items->Clear(); indexZ = 0; } ``` ::: ::: spoiler Save all BMP as files shown in ListBox1 (in the same directory as the ~.exe) ```cpp= void __fastcall TForm1::Button8Click(TObject *Sender) { int i; for (i=0; i<ListBox1->Items->Count; i++) { String sName = ListBox1->Items->Strings[i]; sName += ".bmp"; Memo1->Lines->Add(sName); Image1->Picture->Assign(Z[i]); Image1->Picture->SaveToFile(sName); } } ``` ![](https://hackmd.io/_uploads/ByI3uDYeT.bmp) ![](https://hackmd.io/_uploads/SyPn_Dtep.bmp) ![](https://hackmd.io/_uploads/H1w2uwtg6.bmp) ::: ## Reference Color models: https://media.defense.gov/2020/Sep/21/2002502368/1920/6000/0/200921-D-PA656-0002.JPG Builder strings http://www.functionx.com/bcb/topics/strings.htm BMP in C++ Builder https://learncplusplus.org/learn-about-bitmap-operations-in-c-builder-firemonkey/ ## Schedule 1. Secret sahring: an introduction, Problem-based learning, C++ builder, *Design 2 shares' sharing using transparencies* 2. Secret sharing vs. Cryptography, Originality from Noar-Shamir, *Load an image as an image in builder* 3. (k,n) access structures, Encoding/Decoding in (2, 2)-VCS, *Load a color image and make it 8-colors" #### Rename all objects and save the project ![](https://hackmd.io/_uploads/BJ6YHwlbT.png) ![](https://i.imgur.com/VQaSXSb.png) ```cpp= void __fastcall TForm1::Button4Click(TObject *Sender) { int i, j, gray, rr, gg, bb; Y = new Graphics::TBitmap(); Y->Width = BMP->Width; Y->Height = BMP->Height; for (i=0; i<BMP->Height; i++) for (j=0; j<BMP->Width ; j++) { rr = GetRValue(BMP->Canvas->Pixels[i][j]); gg = GetGValue(BMP->Canvas->Pixels[i][j]); bb = GetBValue(BMP->Canvas->Pixels[i][j]); gray = ((rr+gg+bb)/3 <= 127) ? 0 : 255; Y->Canvas->Pixels[i][j] = (TColor)RGB(gray, gray, gray); } Image1->Picture->Assign(Y); ListBox1->Items->Add("Y"); } ``` ![](https://i.imgur.com/bp0NM2Z.png) ![](https://i.imgur.com/7K4T2DZ.png) ![](https://i.imgur.com/m4XBRXg.png) ![](https://i.imgur.com/QmqhKzi.png) ![](https://hackmd.io/_uploads/rJ7KBdgZT.png =80%x)

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully