您好,欢迎访问三七文档
当前位置:首页 > 办公文档 > 会议纪要 > 基于偏微分方程的图像处
1.(1)clear;image_I=imread('C22.bmp');subplot(2,2,1);imshow(image_I);matrix_R(:,:,1)=image_I(:,:,1);matrix_R(:,:,2)=0;matrix_R(:,:,3)=0;subplot(2,2,2);imshow(matrix_R);title('R分量');matrix_G(:,:,2)=image_I(:,:,2);matrix_G(:,:,1)=0;matrix_G(:,:,3)=0;subplot(2,2,3);imshow(matrix_G);title('G分量');matrix_B(:,:,3)=image_I(:,:,3);matrix_B(:,:,1)=0;matrix_B(:,:,2)=0;subplot(2,2,4);imshow(matrix_B);title('B分量')R分量G分量B分量(2)clear;Image=imread('I22_256.bmp');imshow(Image);[m,n]=size(Image);image11=Image;fori=1:mforj=1:nimage12(i,j)=image11(i,n-j+1);endendforj=1:nfori=1:mimage21(i,j)=image11(m-i+1,j);image22(i,j)=image12(m-i+1,j);endendimage1=[image11,image12];image2=[image21,image22];image=[image1;image2];figureimshow(image)2.clear;Image=imread('I22_256.bmp');Image1=0.5*double(Image);subplot(3,2,1);imshow(Image);subplot(3,2,2);imhist(Image);subplot(3,2,3);imshow(uint8(Image1));image1=uint8(Image1);imwrite(image1,'I22_256_1.bmp')subplot(3,2,4);imhist(image1);Image_hist=histeq(image1);subplot(3,2,5);imshow(Image_hist);imwrite(Image_hist,'I22_256_2.bmp')subplot(3,2,6);imhist(Image_hist);010000100200010002000010020001000200001002003.(1)functionlevel(image_name,N)%求一图像的水平集、线%输入参数:image_name---图像文件名%:N---阀值(0-255)ifnargin1disp('请输入文件名!!!');return;elseifnargin2N=128;endimage_input=imread(image_name);subplot(2,2,1);imshow(image_input);title('原图像');[size_m,size_n]=size(image_input);matrix_temp=zeros(size_m,size_n);%Çóˮƽ¼¯forrow=1:size_mforcol=1:size_nifimage_input(row,col)Nmatrix_temp(row,col)=1;endendendsubplot(2,2,2);imshow(matrix_temp,[]);title('图像的水平集');imwrite(matrix_temp,'level_setzhan.bmp');%图像矩阵扩展赋值便于处理边界matrix_ex=zeros(size_m+2,size_n+2);forrow=1:size_mforcol=1:size_nmatrix_ex(row+1,col+1)=matrix_temp(row,col);endend%四邻域反填充得水平线matrix_new=matrix_temp;forrow=2:size_m+1forcol=2:size_n+1ifmatrix_ex(row+1,col)==0&matrix_ex(row-1,col)==0&matrix_ex(row,col+1)==0&matrix_ex(row,col-1)==0matrix_new(row-1,col-1)=1;endendendsubplot(2,2,3);imshow(matrix_new,[]);title('图像的水平线');%imwrite(matrix_new,'level_line.bmp');%求图像的等高线contour=zeros(size_m,size_n);forrow=1:size_mforcol=1:size_nifimage_input(row,col)==Ncontour(row,col)=1;endcontour(row,col)=1-contour(row,col);endendsubplot(2,2,4);imshow(contour,[]);title('图像的等高线');%imwrite(contour,'contour.bmp');level('I22_256.bmp',100)原图像图像的水平集图像的水平线图像的等高线(2)functionlevel_line_set(image_name)%求一图像的阀值N取各值所对应的水平线的叠加%输入参数:image_name---图像文件名image_input=imread(image_name);%不变量[size_m,size_n]=size(image_input);%不变量matrix_out=zeros(size_m,size_n);%循环中不需重新初始化的变量%输出矩阵初始化(白)forrow=1:size_mforcol=1:size_nmatrix_out(row,col)=1;endendmatrix_ex=zeros(size_m+2,size_n+2);%扩展矩阵subplot(1,2,1);imshow(image_input);title('原图像');forN=1:32:255%N为相应阀值matrix_temp=zeros(size_m,size_n);%重新初始化(黑)forrow=1:size_mforcol=1:size_nifimage_input(row,col)=Nmatrix_temp(row,col)=1;%求水平集-----endendend%图像矩阵扩展赋值便于处理边界forrow=1:size_mforcol=1:size_nmatrix_ex(row+1,col+1)=matrix_temp(row,col);endend%四邻域(黑区域填白)反填充得水平线matrix_new=matrix_temp;forrow=2:size_m+1forcol=2:size_n+1ifmatrix_ex(row+1,col)==0&matrix_ex(row-1,col)==0&matrix_ex(row,col+1)==0&matrix_ex(row,col-1)==0matrix_new(row-1,col-1)=1;%填白endendendmatrix_out=min(matrix_out,matrix_new);%各级水平线叠加endmatrix_out(1,1)=0;matrix_out(2,1)=1;subplot(1,2,2);imshow(matrix_out,[]);title('图像部分水平集的叠加');level_line_set('I22_256.bmp')原图像图像部分水平集的叠加4.Image=imread('I22_256.bmp');subplot(3,2,1);imshow(Image,[]);%原图像title('原图像');subplot(3,2,2);imhist(Image);noise_g=imnoise(Image,'gaussian',0,0.01);%增加高斯白噪声subplot(3,2,3);imshow(noise_g,[]);title('高斯白噪声');imwrite(noise_g,'I22_256_g.bmp');subplot(3,2,4);imhist(noise_g);noise_s=imnoise(Image,'salt&pepper',0.02);subplot(3,2,5);imshow(noise_s,[]);title('黑白象素点噪声(椒盐)');imwrite(noise_s,'I22_256_s.bmp')subplot(3,2,6);imhist(noise_s);原图像010000100200高斯白噪声0100020000100200黑白象素点噪声(椒盐)0100001002005.functionaver_filter(Image_name,N,out_filename)%非线性平滑滤波器G1平均%输入参数文件名N为模板大小(正奇数)%读取图像-------------ifnargin3disp('输入参数错误!!!');return;endimage=imread(Image_name);subplot(1,2,1);imshow(image,[]);title('原图像');ifisrgb(image)image=rgb2gray(image);end%图像扩展--------------[size_m,size_n]=size(image);image_ex=zeros(size_m+N-1,size_n+N-1);%赋值forrow=1:size_mforcol=1:size_nimage_ex(row+(N-1)/2,col+(N-1)/2)=image(row,col);endend%对每个象素------------------pattern_plate=zeros(N,N);%模板image_new=zeros(size_m,size_n);%滤后图像矩阵forrow=1:size_mforcol=1:size_n%取模板的元素forrow_p=1:Nforcol_p=1:Npattern_plate(row_p,col_p)=image_ex(row+row_p-1,col+col_p-1);endend%求模板的平均值得滤后图像矩阵image_new(row,col)=mean2(pattern_plate);endend%输出---------------subplot(1,2,2)imshow(image_new,[]);title('均值滤波图像');imwrite(uint8(image_new),out_filename)functionweight_filter(Image_name,flag,out_filename)%用各模板进行去噪和锐化%输入参数Image_name文件名%flag模板类型标志1~4ifnargin3disp('请按参数格式输入参数!!!');return;endifflag~=1&flag~=2&flag~=3&flag~=4disp('参数flag输入错误!!!');return;endN=3;pattern_plate=zeros(N,N);%模板%各类模板ifflag==1pattern_plate=[1/91/91/9;1/91/91/9;1/91/91/9];elseifflag==2pattern_plate=[1/161/81/16;1/81/41/8;1/161/81/16];%平滑滤波器elseifflag==3pattern_plate
本文标题:基于偏微分方程的图像处
链接地址:https://www.777doc.com/doc-3531595 .html