# Integrating Visual Cryptography for Efficient and Secure Image Sharing on Social Networks
## 3 Proposed Method
### Prespeneration of Encrypted Images  
VC requires converting images into binary images for encryption. The halftone algorithm transforms continuous-tone images into binary images. Taking grayscale images as an example, the algorithm transforms the pixel values of the image from continuous to discrete, representing the image with only white or black pixels. The most common halftoning algorithm is error diffusion (ED) [18]. Different from the standard binary image, a halftone image can appear continuous-tone when viewed from a distance due to the low filtering capability of the human visual system. This algorithm reduces the loss of image details by diffusing the error of the current pixel to surrounding pixels in a specific ratio. For an \(I\) image in grayscale, we obtain an \(I_{h}\) image in corresponding halftones by minimizing the following objective function in Equation (4):  
\[\text{Obj}(I,I_{h})=w_{g}G(I,I_{h})+w_{t}(1-\text{MSSIM}(I,I_{h})) \tag{4}\]  
where \(G(I,I_{h})\) measures the similarity of the original and halftone images, and \(MSSIM(I,I_{h})\) measures the average structure similarity. \(w_{t}\) and \(w_{g}\) are weighting factors that balance the contributions of structural similarity and tone preservation to the overall quality score. The values of the \(w_{t}\) and \(w_{g}\) are 0.2 and 0.3, respectively. Homogenization can start with any 2D image that matches the overall grayscale ratio of the original image. This involves randomly dispersing black and white pixels while maintaining the global grayscale. To accelerate convergence, outcomes from established halftoning methods like ED are utilized. The Structural Similarity Index Measure (SSIM) quantitatively assesses structural differences between the halftone output and the original grayscale image. SSIM evaluates localized structural similarity in the neighborhoods of corresponding pixel pairs from the two images, with an \(11\times 11\) window. It breaks down similarity evaluation into three components: luminance \(l(x,y)\), contrast \(c(x,y)\), and structure \(s(x,y)\). Assuming \(x\) and \(y\) are two non-negative aligned images, each with \(N\) elements, we first compare their brightness. This is estimated with the weighted average intensity, \(\mu_{x}=\sum_{i=1}^{N}\omega_{i}x_{i}\), typically with a normalized Gaussian weighting for \(\omega_{i}\). The brightness comparison function, \(l(x,y)\), depends on \(\mu_{x}\) and \(\mu_{y}\), as shown in Equation (5):  
\[l(x,y)=\frac{2\mu_{x}\mu_{y}+k_{1}}{\mu_{x}^{2}+\mu_{y}^{2}+k_{1}} \tag{5}\]  
where \(k_{1}\) is a small constant to avoid singularity. There is a similar definition for contrast \(c\) (\(x,y\)). As shown in Equation (6), it takes standard deviations \(\sigma x\) and \(\sigma y\) as estimates of signal contrast. \[ \begin{split} c(x,y)=\frac{2\sigma_{x}\sigma_{y}+\kappa_{2}}{ \sigma_{x}^{2}+\sigma_{y}^{2}+\kappa_{2}},\\ \sigma_{x}=\left(\sum_{i=1}^{N}\omega_{i}(x_{i}-\mu_{x})^{2} \right)^{\frac{1}{2}}\end{split}  \tag{6}\]  
where \(\kappa_{2}\) is a small constant that prevents singularity. Image correlation serves as an effective metric for assessing structural similarity. We can define it in Equation (7):  
\[ \begin{split} s(x,y)=\frac{\sigma_{xy}+\kappa_{3}}{\sigma_{x} \sigma_{y}+\kappa_{3}},\\ \sigma_{xy}=\sum_{i=1}^{N}\omega_{i}(x_{i}-\mu_{x})(y_{i}-\mu_{y} )\end{split}  \tag{7}\]  
where \(\sigma_{xy}\) defines the inner product, and \(k_{3}\) is a small constant avoiding singularity. \(k_{1}\) and \(k_{2}\) are usually set to 0.01 and 0.03, while \(k_{3}=k_{2}/2=0.015\). The SSIM value ranges between \(-1\) and \(1\), where a value of \(1\) indicates perfect similarity. SSIM is defined in Equation (8):  
\[\text{SSIM}(x,y)=l(x,y)\cdot c(x,y)\cdot s(x,y) \tag{8}\]  
Changes in brightness or contrast do not affect the structure of images. The mean SSIM (MSSIM) is calculated by averaging all pixel values to assess overall image quality, with values ranging from 0 to 1, where higher values indicate greater similarity.