matlab程序(图片处理)>>[vid,audio]=mmread('40000.avi');%读视频mmplay(vid);>>functionavi2bmp(avifile,bmpfile)%提取帧>>mov=mmread('40000.avi');%读取灰色视频aviread读取二值视频>>temp=size(mov);>>fnum=temp(2);>>fori=1:fnum,strtemp=strcat(bmpfile,int2str(i),'.bmp');imwrite(mov(i).cdata(:,:,:),strtemp)endI=imread('koala.jpg');%转为二值图subplot(121);imshow(I);level=graythresh(I)BW=im2bw(I,level);subplot(122);imshow(BW);clearall;%鼠标裁剪1closeall;I=imread('0666.jpg');figure,imshow(I);%image(I);可以形成坐标轴式图像I2=imcrop();%裁剪可分开运行figure,imshow(I2)clc;clearall;%鼠标裁剪2figure,imshow('pout.tif');h=imcrop();figure;imshow(h);I=imread('666.jpg');%裁剪固定区域I2=imcrop(I,[259.6780.85317.945]);imshow(I);figure,imshow(I2);mov=mmread('40000.avi');%把视频转化为图像。fnum=size(mov.frames,2);fori=1:fnumstrtemp=strcat(int2str(i),'.','JPG');imwrite(mov.frames(i).cdata(:,:,:),strtemp);%2---11一个周期endfnum=1001;%用循环把1001张转化为二值图并保存I=cell(1,fnum);J=cell(1,fnum);fori=1:fnumimageName=strcat(num2str(i),'.jpg');I{i}=imread(imageName);level=graythresh(I{i});J{i}=im2bw(I{i},level);st=strcat('aa',int2str(i),'.','jpg');imwrite(J{i},st);endI=imread('666.JPG');%把一桢化为二值图imshow(I);BW=im2bw(I,0.1686);imshow(BW);level=graythresh(imread('666.jpg'))%计算二值图的level阙值t=linspace(0,20*pi,10000);%三维轨迹动画二维的用plot(x,y);comet(x,y,p)p默认为0.1>>x=sin(t);y=cos(t);>>plot3(x,y,t),axissquare,holdon;%去掉holdon可以自动画,不会产生轨迹>>comet3(x,y,t,0.5);>>h=waitbar(0,'pleasewait...');%建立waitbarfori=1:100,ifi>=90waitbar(i/100,h,'快完成了...');pause(0.05);elsestr=['当前已完成',num2str(i),'%...'];waitbar(i/100,h,str);pause(0.05);endendclose(h);ifget(gco,'value')==1%radiobuttongrid代码set(findobj('tag','radiobuttongrid'),'value',0);gridonenddList=dir('*.jpg');%批量处理%如需其它图片格式支持,可以自己【重载dir()】函数,实现查找所有图片文件的功能,%如果图片是其它路径,可以用["路径"".扩展名"]字符串来实现。k=length(dList);fori=1:1:kimage_data{i}=imread(dList(i).name);end%所有的图片数据,已经保存在了cell变量image_data里面了。%下面演示如何使用%每隔一秒钟显示一幅图片forj=1:1:kimage(image_data{j});pause(1);endpic=imread('666.jpg');%求任意裁剪图片的质心[x,y,z]=size(pic);if(z~=1)pic=rgb2gray(pic);endimshow(pic);im=pic;[temp1,temp2,p,rect]=imcrop(im);figure,imshow(p)title('*代表其质心');[rows,cols]=size(p);meanx=(1+cols)/2;meany=(1+rows)/2;holdonplot(meanx,meany,'*')originalx=meanx+round(rect(1))-1;originaly=meany+round(rect(2))-1;figureimshow(pic)holdonplot(originalx,originaly,'*')fnum=str2double(get(handles.edit11,'String'));%得到edit11中数字count=0;%初定义循环次数fork=1:fnum%求任意裁剪图片的质心imageName=strcat(num2str(k),'.jpg');%定义输入图像名称字符串Image=imread(imageName);ImageGray=rgb2gray(Image);%灰色I2=imcrop(ImageGray,[250806843.13]);%特定区域裁剪Data=dither(I2);[r,c]=size(Data);[X,Y]=meshgrid(1:c,1:r);%生成网格阵x0=sum(sum(X.*Data))/sum(sum(Data));%图像质心y0=sum(sum(Y.*Data))/sum(sum(Data));holdon;plot(x0,y0,'*');pause(1/40);count=count+1;set(handles.edit10,'string',count)%把循环次数在edit10输出end[filenamepathname]=uiputfile({'*.txt','txt-files(*.txt)';'*.*','All-files(*.*)'},'SaveaFile');%打开选择格式选项str=strcat(pathname,filename);data1=get(handles.edit11,'string');%得到edit数据data2=get(handles.edit13,'string');data3=get(handles.edit14,'string');data4=get(handles.edit15,'string');%把edit数据写入textdata5=get(handles.edit16,'string');data6=get(handles.edit12,'string');data7=get(handles.edit17,'string');fin=fopen(str,'wt');%打开空文件fprintf(fin,'设定次数=%s\n',data1);fprintf(fin,'Xmax=%s\n',data2);fprintf(fin,'Ymax=%s\n',data3);fprintf(fin,'Xmin=%s\n',data4);fprintf(fin,'Ymin=%s\n',data5);fprintf(fin,'振幅X=%s\n',data6);%写入数据fprintf(fin,'振幅Y=%s\n',data7);fclose(fin);%关闭ifget(gcbo,'Value')==1;%设置toobuttonset(handles.pushbutton3,'string','Gridon');gridon;elseset(handles.pushbutton3,'string','Gridoff');gridoff;傅里叶变换a=load('1001.txt');%读数据t=a(:,1)';%时间x=a(:,2)';%数据fs=40000y=fft(x,1001);%fft是matlab中傅里叶变换的命令,abs是求模,我画的是幅值谱f=(0:length(y)-1)*fs/length(y);%频谱图横轴,总共49个点,最大值是fs,每个点就是fs/49figure();%画在一起了subplot(211);plot(t,x);holdon;comet(t,x);title('时间振幅图');xlabel('时间S');ylabel('振幅');subplot(212);plot(f,abs(y)/max(abs(y)),'r');holdon;comet(f,abs(y)/max(abs(y)));title('频率振幅图');xlabel('频率HZ');本人在用GUI编制图像处理程序中学到了不少图像操作的技巧,比如图像的导入,显示,保存,放大,拖动,旋转和选择图像的某一矩形区域或某一点。大家也一定在使用GUI处理图像中或多或少遇到这些问题,现在我把我的经验与大家分享:1.图像的导入,显示,保存:将电脑中的图片导入matlab并显示,或将处理好的图像保存在电脑中是用GUI处理图像很基本的问题。1.1导入图像:在GUI中画出一个pushbutton,命名为loadimage,Callback写为:复制内容到剪贴板代码:[filename,path]=uigetfile('*.tif','loadimagefiles');%弹出文件获取对话框,默认图片为tif格式ifisequal(filename,0)||isequal(path,0)disp('Filenotfound');%若没有选择图片则显示'Filenotfound'并返回returnelsefile=[pathfilename];%file为文件的路径+文件名endI=imr