function [share1, share2, share12] = VisCrypt(inImg) s = size(inImg); share1 = zeros(s(1), (2 * s(2))); share2 = zeros(s(1), (2 * s(2))); %%White Pixel Processing %White Pixel share combinations disp('White Pixel Processing...'); s1a=[1 0]; s1b=[1 0]; [x,y] = find(inImg == 1); len = length(x); for i=1:len a=x(i);b=y(i); pixShare=generateShare(s1a,s1b); share1((a),(2*b-1):(2*b))=pixShare(1,1:2); share2((a),(2*b-1):(2*b))=pixShare(2,1:2); end %Black Pixel Processing %Black Pixel share combinations disp('Black Pixel Processing...'); s0a=[1 0]; s0b=[0 1]; [x,y] = find(inImg == 0); len = length(x); for i=1:len a=x(i);b=y(i); pixShare=generateShare(s0a,s0b); share1((a),(2*b-1):(2*b))=pixShare(1,1:2); % share2((a),(2*b-1):(2*b))=pixShare(2,1:2); end share12=bitor(share1, share2); share12 = ~share12; disp('Share Generation Completed.');
时间: 2024-03-15 07:42:34 浏览: 20
该代码可能存在一些错误,以下是我发现的问题:
1. 代码中的 `generateShare` 函数没有定义或提供,如果没有在其他地方定义该函数,代码将无法运行。
2. 在白色像素处理循环中, `s1a` 和 `s1b` 始终都是 `[1 0]`,因此无论循环多少次,白色像素的共享图像都将相同。这可能不是您期望的结果。
3. 在黑色像素处理循环中, `s0a` 和 `s0b` 始终都是 `[1 0]` 和 `[0 1]`,因此黑色像素的共享图像也将重复。同样,这可能不是您期望的结果。
4. 在黑色像素处理循环中,为 `share2` 赋值的语句被注释掉了,这意味着黑色像素没有生成第二个共享图像。
5. 在生成 `share12` 的过程中,使用了位或运算符 `bitor`,但在下一行中又对 `share12` 取反,这可能导致共享图像的生成出现问题。
相关问题
function [share1, share2] = VisCrypt(inImg) s = size(inImg); share1 = zeros(s(1), (s(2))); share2 = zeros(s(1), (s(2))); % share1 = zeros(s(1), (2 * s(2))); % share2 = zeros(s(1), (2 * s(2))); %%White Pixel Processing %White Pixel share combinations disp('White Pixel Processing...'); s1a=[1 0]; s1b=[1 0]; [x y] = find(inImg == 1); len = length(x); for i=1:len a=x(i);b=y(i); pixShare=generateShare(s1a,s1b); share1((a),(2*b-1):(2*b))=pixShare(1,1:2); share2((a),(2*b-1):(2*b))=pixShare(2,1:2); end %Black Pixel Processing %Black Pixel share combinations disp('Black Pixel Processing...'); s0a=[1 0]; s0b=[0 1]; [x y] = find(inImg == 0); len = length(x); for i=1:len a=x(i);b=y(i); pixShare=generateShare(s0a,s0b); share1((a),(2*b-1):(2*b))=pixShare(1,1:2); share2((a),(2*b-1):(2*b))=pixShare(2,1:2); end share12=bitor(share1, share2); share12 = ~share12; disp('Share Generation Completed.');
这段代码实现的是一种基于视觉加密算法的图像加密方法。具体来说,代码中定义了一个名为 "VisCrypt" 的函数,该函数接受一个输入图像 "inImg",并返回两个输出图像 "share1" 和 "share2",这两个图像是经过加密处理的分享图像。可以将 "share1" 和 "share2" 分别发送给两个不同的接收方,只有同时使用这两个分享图像才能还原出原始的输入图像。
代码中首先对输入图像中的白色像素和黑色像素分别进行处理,生成对应的分享图像 "share1" 和 "share2"。其中,白色像素的分享组合为 [1 0] 和 [1 0],黑色像素的分享组合为 [1 0] 和 [0 1]。然后将 "share1" 和 "share2" 进行按位或运算并取反,得到最终的分享图像 "share12",这个分享图像就是最终需要发送给接收方的分享图像。
需要注意的是,代码中使用了一个名为 "generateShare" 的函数,这个函数没有在代码中给出,需要根据具体情况补充代码。此外,还需要保证输入的图像 "inImg" 只包含黑色和白色两种像素。
function [share1, share2, share12] = VisCrypt(inImg) s = size(inImg); share1 = zeros(s(1), (2 * s(2))); share2 = zeros(s(1), (2 * s(2))); %%White Pixel Processing %White Pixel share combinations disp('White Pixel Processing...'); s1a=[1 0]; s1b=[1 0]; [x y] = find(inImg == 1); len = length(x); for i=1:len a=x(i);b=y(i); pixShare=generateShare(s1a,s1b); share1((a),(2*b-1):(2*b))=pixShare(1,1:2); share2((a),(2*b-1):(2*b))=pixShare(2,1:2); end %Black Pixel Processing %Black Pixel share combinations disp('Black Pixel Processing...'); s0a=[1 0]; s0b=[0 1]; [x y] = find(inImg == 0); len = length(x); for i=1:len a=x(i);b=y(i); pixShare=generateShare(s0a,s0b); share1((a),(2*b-1):(2*b))=pixShare(1,1:2); share2((a),(2*b-1):(2*b))=pixShare(2,1:2); end share12=bitor(share1, share2); share12 = ~share12; disp('Share Generation Completed.');
这段代码实现了一种称为“可视加密”的图像加密方法。具体实现过程如下:
1. 首先声明了三个变量 share1,share2 和 share12,分别用于保存加密后的两个分享和它们的逻辑 XOR 运算结果。
2. 接下来通过使用 find 函数查找输入图像中所有的白色像素和黑色像素,并将它们的坐标保存在变量 x 和 y 中。
3. 然后分别对于白色像素和黑色像素,生成它们的两个分享 share1 和 share2。生成分享的方法是调用 generateShare 函数,该函数接受两个参数 s1a 和 s1b(或 s0a 和 s0b),并返回一个 2x2 的矩阵,其中第一行是分享 1,第二行是分享 2。生成的分享将被保存在 share1 和 share2 中。
4. 最后,通过按位或运算 bitor 对 share1 和 share2 进行组合,将结果保存在变量 share12 中。注意,在此之前,还需要将 share12 取反,以确保分享组合后的图像与原始图像不同。
总之,这段代码实现了一种基于分享的可视加密算法,可用于保护图像的机密性。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)