%%Matlab读取图片:
>> mat=imread('pic1.png');
>> imshow(mat)
>> size(mat)
ans =
906 947 3
• gray2ind - intensity image to index image
• im2bw - image to binary
• im2double - image to double precision
• im2uint8 - image to 8-bit unsigned integers
• im2uint16 - image to 16-bit unsigned integers
• ind2gray - indexed image to intensity image
• mat2gray - matrix to intensity image
• rgb2gray - RGB image to grayscale
• rgb2ind - RGB image to indexed image
>> I=imread('pic1.png');
>> figure,imshow(I);
>> gI=rgb2gray(I);
>> [X,map]=gray2ind(gI,16);
>> figure,imshow(X,map);
>> figure,imshow(gI);
结果:
>> [X,map]=gray2ind(gI,8);
>> imshow(X,map)
>> [X,map]=gray2ind(gI,256);
>> imshow(X,map)
>> bI=im2bw(gI,0.5);
>> imshow(bI);
>> I0=imread('pic3.png');
>> I1=imread('pic3-1.png');
>> I2=imread('pic3-2.png');
>> I3=imread('pic3-3.png');
>> figure,image(I1),truesize,title('I1-image'),xlabel('I1')
>> figure,image(I2),truesize,title('I2-image'),xlabel('I2')
>> figure,image(I3),truesize,title('I3-image'),xlabel('I3')
>> mI=uint8(double(I1)+double(I2)+double(I3));
>> figure,image(mI),truesize,title('mI-image'),xlabel('mI')
将三张残缺的图叠加:
结果:
>> aI2=imadjust(I0,[],[],0.5);
>> figure,imshow(aI2)
>> aI3=imadjust(I0,[],[],2);
>> figure,imshow(aI3)
>> aI1=imadjust(I0,[0,1],[1,0]);
>> figure,imshow(aI1)
结果:
>> imhist(I0)
>> figure,imshow(I0)
p=3;q=5;
I0=imread('pic3.png');
ii=1;
I1=zeros(round(size(I0,1)*p/q),round(size(I0,2)*p/q),3);
for i=1:q:size(I0,1)-1
jj=1;
for j=1:q:size(I0,2)-1
I1(ii:ii+p-1,jj:jj+p-1,:)=double(I0(i:2:i+q-1,j:2:j+q-1,:));
jj=jj+p;
end
ii=ii+p;
end
figure
image(I0)
% truesize
figure
image(uint8(I1))
% truesize
size(I0),size(I1)
I=imread('pic1.png');
I=I0;
I0=double(I0);
I1=zeros(size(I0,1)*2,size(I0,2)*2,3);
[r,c]=meshgrid(1:size(I0,2),1:size(I0,1));
rc=linspace(1, size(I,1), size(I,1)*2);
cc=linspace(1, size(I,2), size(I,2)*2);
[r_new,c_new]=meshgrid(cc,rc);
rc=linspace(1, size(I0,1), size(I0,1)*2);
cc=linspace(1, size(I0,2), size(I0,2)*2);
[r_new,c_new]=meshgrid(cc,rc);
I1(:,:,1)=interp2(r,c,I0(:,:,1),r_new,c_new,'spline');
I1(:,:,2)=interp2(r,c,I0(:,:,2),r_new,c_new,'spline');
I1(:,:,3)=interp2(r,c,I0(:,:,3),r_new,c_new,'spline');
imshow(uint8(I1))
size(I1)
>> I0=imread('pic3.png');
figure,imshow(I0)
nI = imnoise(I0, 'salt & pepper', 0.01);
figure,imshow(nI)
nII = imnoise(I0, 'gaussian', 0.01);
figure,imshow(nII)
I=imread('pic3.png');
I0=rgb2gray(I);
nII = imnoise(I0, 'gaussian', 0.01);
aI=imfilter(nII,fspecial('average',[3,3]));
figure,imshow(nII),figure,imshow(aI)
I=imread('pic3.png');
I0=rgb2gray(I);
nII = imnoise(I0, 'salt & pepper', 0.01);
aI=imfilter(nII,fspecial('average',[3,3]));
figure,imshow(nII),figure,imshow(aI)
I=imread('pic3.png');
I0=rgb2gray(I);
nII = imnoise(I0, 'salt & pepper', 0.01);
k2=medfilt2(nII ,[5,5]);
figure,imshow(nII),figure,imshow(k2)
I0=imread('pic3.png');
I0(100:105,800:808,:)=0;
figure,imshow(I0)
w=[-1 -1 -1;-1 8 -1;-1 -1 -1];
g=abs(imfilter(I0,w));
T=max(g(:));
g=(g>=T);
imshow(uint8(g))
f=imread('pic4.png');
figure,imshow(f);
w = [2 -1 -1; -1 2 -1;-1 -1 2 ];
g = imfilter(double(f),w);
figure,imshow(g)
gtop = g(1:120,1:120);
figure , imshow(gtop)
gbot = g(end-119:end, end-119:end);
figure,imshow(gbot)
g = abs(g);
figure,imshow(g)
T = max (g(:));
g = g >= T;
figure, imshow(g)
I=imread('pic4.png');
I0=rgb2gray(I);
subplot(231);
imshow(I);
BW1=edge(I0,'Roberts',0.16);
subplot(232);
imshow(BW1);
title('Roberts')
BW2=edge(I0,'Sobel',0.16);
subplot(233);
imshow(BW2);
title('Sobel')
BW3=edge(I0,'Prewitt',0.16);
subplot(234);
imshow(BW3);
title('Prewitt');
BW4=edge(I0,'LOG',0.012);
subplot(235);
imshow(BW4);
title('LOG')
BW5=edge(I0,'Canny',0.2);
subplot(236);
imshow(BW5);
title('Canny');