%% 读取图片
clc, clear, close all
a1=imread('000.bmp');
[m,n]=size(a1);
%% 批量读取图片
dirname = 'ImageChips';
files = dir(fullfile(dirname, '*.bmp'));
a=zeros(m,n,19);
pic=[];
for ii = 1:length(files)
filename = fullfile(dirname, files(ii).name);
a(:,:,ii)=imread(filename);
pic=[pic,a(:,:,ii)];
end
double(pic);
figure
imshow(pic,[])
dir(xxx)返回其中文件名或所有文件夹下所有文件名
fullfile(a,b,c)合成一个地址ac
a(:,:,1)分块的矩阵(其中的第一块)
imread('xxx.jpg');imshow(pic,[])前者为读取图片像素,后者为展示图片
原理在于将图片变为矩阵,通过拼接ju’z矩阵来转换为图片。
批量行拼接图片
function ConnectImages()
%% 读取图片
clc, clear, close all
%% 批量拼接图片
files = dir('*.jpg');maxrows=0;maxlines=0;
pic=[];rows=[];lines=[];
for ii = 1:length(files)
filename = fullfile(files(ii).name);
lite=imread(filename);
[m,n]=size(lite);
rows=[rows m];lines=[lines n];
end
maxrows=max(rows);
for ii = 1:length(files)
filename = fullfile(files(ii).name);
lite2=imread(filename);
[m,n]=size(lite2);
temp=[lite2 ];
final=[temp;255.*ones(maxrows-m,n/3,3)];
pic=[pic,final];
end
figure
imshow(pic,[])
end
批量行加密图片
files = dir('*.jpg');
for ii = 1:length(files)
filename = fullfile(files(ii).name);
lite=imread(filename);
[m,n]=size(lite);
encry=zeros(m,n/3,3);
key=randsample(m,m)';
for k=1;3
encry(:,:,k)=lite(key,:,k);
end
encry=uint8(encry);
figure
imshow(encry);
end