matlab图像处理

    技术2024-11-13  9

    %保存不同格式,并比较大小 %{ image=imread('flower.tif'); imwrite(image,'flower.jpg'); imwrite(image,'flower.bmp'); B_info=imfinfo('flower.bmp'); J_info=imfinfo('flower.jpg'); T_info=imfinfo('flower.tif'); [T_info.FileSize,J_info.FileSize,B_info.FileSize] B_image=imread('flower.bmp'); J_image=imread('flower.jpg'); T_image=imread('flower.tif'); subplot(1,3,1),imshow(T_image),title('tif格式'); subplot(1,3,2),imshow(J_image),title('jpg格式'); subplot(1,3,3),imshow(B_image),title('bmp格式'); %} %转化为二值图像 %{ Lenna=imread('Lenna.jpg'); cameman=imread('cameman.jpg'); L_bw=im2bw(Lenna,0.5); C_bw=im2bw(cameman,0.5); subplot(2,2,1),imshow(Lenna),title('Lenna'); subplot(2,2,2),imshow(cameman),title('Lenna BW'); subplot(2,2,3),imshow(L_bw),title('cameman'); subplot(2,2,4),imshow(C_bw),title('cameman BW'); %} %RGB转YCbCr %{ image=imread('flower.tif'); YCbCr=rgb2ycbcr(image); YCbCr_Y=YCbCr(:,:,1); YCbCr_Cb=YCbCr(:,:,2); YCbCr_Cr=YCbCr(:,:,3); subplot(2,2,1),imshow(YCbCr_Y),title('Y'); subplot(2,2,2),imshow(YCbCr_Cb),title('Cb'); subplot(2,2,3),imshow(YCbCr_Cr),title('Cr'); %} %像素取反 %{ image=imread('flower.tif'); info=imfinfo('flower.tif'); J=double(image); J2=imcomplement(image); T=255*ones(size(image)); J=T-J; J=uint8(J); % for k=1:3 % for i=1:1:info.Height % for j=1:1:info.Width % J(i,j,k)=255-J(i,j,k); % end % end % end subplot(1,3,1),imshow(J),title('取各个像素点计算取反'); subplot(1,3,2),imshow(J2),title('自带函数处理'); subplot(1,3,3),imshow(image),title('原图'); %} %RGB通道分离 image = imread('flower.tif'); image_r=image;image_r(:,:,[2 3])=0;%使GB通道为0,是的产生的图片的只显示红色 image_g=image;image_g(:,:,[1 3])=0; image_b=image;image_b(:,:,[1 2])=0; R=image(:,:,1); G=image(:,:,2); B=image(:,:,3); %产生灰度图 %zero=zeros(size(image_r)); %R=cat(3,image_r,zero,zero); %G=cat(3,zero,image_g,zero); %B=cat(3,zero,zero,image_b); %RGB=cat(3,image_r,image_g,image_b); subplot(2,2,1),imshow(image_r),title('Red'); subplot(2,2,2),imshow(image_g),title('Green'); subplot(2,2,3),imshow(image_b),title('Blue'); subplot(2,2,4),imshow(image),title('RGB'); %不同采样频率比较 Lenna=imread('Lenna.jpg'); cameman=imread('cameman.jpg'); L_2=Lenna(1:2:end,1:2:end); L_4=Lenna(1:4:end,1:4:end); L_8=Lenna(1:8:end,1:8:end); L_16=Lenna(1:16:end,1:16:end); C_2=cameman(1:2:end,1:2:end); C_4=cameman(1:4:end,1:4:end); C_8=cameman(1:8:end,1:8:end); C_16=cameman(1:16:end,1:16:end); subplot(2,5,1),imshow(Lenna),title("原"); subplot(2,5,2),imshow(L_2),title("1/2"); subplot(2,5,3),imshow(L_4),title("1/4"); subplot(2,5,4),imshow(L_8),title("1/8"); subplot(2,5,5),imshow(L_16),title("1/16"); subplot(2,5,6),imshow(cameman) ; subplot(2,5,7),imshow(C_2) ; subplot(2,5,8),imshow(C_4) ; subplot(2,5,9),imshow(C_8) ; subplot(2,5,10),imshow(C_16) ;
    Processed: 0.025, SQL: 9