|
量子图像的表示方法:- function LZImg=Img2LZImg(L)
- if(size(L,3)>1)
- L = L(:,:,1); % 灰度图像
- end
- L=double(L);
- [m,n]=size(L); % 图像的行列
- mm = 0:m-1;
- nn = 0:n-1;
- Dmm = dec2bin(mm,log2(m)); % 行列化为二进制
- Dnn = dec2bin(nn,log2(n));
- LZImg=zeros(1,8*m*n);
- Yan_L=dec2bin(L,8); % 灰度值化为二进制
- for i=1:m
- for j=1:n
- x=[];
- Weizhi=strcat(Dnn(j,:),Dmm(i,:)); % 链接行和列,形如丨0010>
- for ii = 1:length(Weizhi) % 位置张量积处理
- if Weizhi(ii) == '0'
- x(:,:,ii) = [1 0]; % 将位置二进制码流对应到基向量x
- else
- x(:,:,ii) = [0 1];
- end
- end
- Ji= kron(x(:,:,1),x(:,:,2));
- for jj = 3:length(Weizhi)
- Ji = kron(Ji,x(:,:,jj));
- end
- Position=Ji;
-
- x=[];
- Yanse=Yan_L((i-1)*m+j,:); % (i,j)处的灰度值
- for yy = 1:length(Yanse) % 颜色张量积处理
- if Yanse(yy) == '0'
- x(1,yy) = 0;
- else
- x(1,yy) = 1;
- end
- end
- Biaodashi=kron(x, Position); % 灰度值与位置的张量积
- LZImg = LZImg + Biaodashi; % 累加
- end
- end
复制代码 量子灰度图像转化为uint8图像显示
- function LZImg1=LZImg2Img(LZImg, m, n)
- % if(size(L,3)>1)
- % L = L(:,:,1); % 灰度图像
- % end
- % L=double(L);
- % [m,n]=size(L); % 图像的行列
- mm = 0:m-1;
- nn = 0:n-1;
- Dmm = dec2bin(mm,log2(m)); % 行列化为二进制
- Dnn = dec2bin(nn,log2(n));
- % LZImg=zeros(1,8*m*n);
- % Yan_L=dec2bin(L,8); % 灰度值化为二进制
- y=[];
- for i=1:m
- for j=1:n
- x=[];
- Weizhi=strcat(Dnn(j,:),Dmm(i,:)); % 链接行和列,形如丨0010>
- for ii = 1:length(Weizhi) % 位置张量积处理
- if Weizhi(ii) == '0'
- x(:,:,ii) = [1 0]; % 将位置二进制码流对应到基向量x
- else
- x(:,:,ii) = [0 1];
- end
- end
- Ji= kron(x(:,:,1),x(:,:,2));
- for jj = 3:length(Weizhi)
- Ji = kron(Ji,x(:,:,jj));
- end
- Position=Ji;
-
- % 将LZImg转化为Img
- x=[];
- y1=0;
- for kk=1:8
- x(1,kk) = LZImg(1, ((kk-1)*(m*n)) + m*(j-1)+i );
- y1 = y1 + x(1,kk).*(2^(8-kk));
- end
- y = [y, y1];
- end
- end
- LZImg1 = reshape(y,[m,n]);
复制代码
参考:链接:https://pan.baidu.com/s/11UfYIZrXb5b-jVlBdedDbg 密码:nvqp
|
|