https://www.yiibai.com/matlab/matlab_commands.html  基础学习网站

https://www.jianshu.com/p/0068dd5a3939

我的电脑里还有一些在火狐浏览器自动下载的地方  好多

(1)图像显示及转换内容
example 1:
>>clear;close all;                          %清除MATLAB所有工作变量,关闭已打开的图形窗口
I=imread('pout.tif');imshow('pout.tif');    %读取图像
whos;                                       %查图像的存储内存
figure,imhist(I);                           %创建图像直方图
I2=hiateq(I);fugure,imshow(I2);             %直方图均衡化,灰度值扩展到整个灰度范围【0,255】,提高对比度
imwrite(I2,'pout2.tif');                    %保存图像
imfinof('pout2.tif')                        %检查新生成图像内容

example 2
>>clear;close all;I=imread('rice.png');imshow('rice.png');  %读取和显示图像
background=imopen(I,strel('disk',15));                      %估计图像背景
I2=imsubtract(I,background);figure,imshow(I2);              %从原始图像中减去背景图像
I3=imadjust(I2,stretchlim(I2),[0 1]);figure,imshow(I3);     %调节图像对比度
level=graythresh(I3);bw=im2bw(I3,level);figure,imshow(bw);  %使用阈值操作将图像转换为二进制图像
【labeled,numobjects】=bwlabel(bw,4);                       %检查图像中的对象个数
grain=imcrop(labeled);                                      %检查标记矩阵
RGB_label=label2rgb(labeled,@spring,'c','shuffle');
imshow(RGB_label);                                          %将标记矩阵转换为伪彩色的索引图像
graindata=regionprops(labeled,'basic')                      %调节图像中对象或区域的属性
allgrains【graindata.area】;max(allgrains)                  %max获得最大的米粒大小
ans=
     695
biggrain=find(allgrains==695)                               %返回最大尺寸米粒的标记号
biggrain=
      68
mean(allgrains)                                             %获取米粒尺寸平均大小
ans=
      249
hist(allgrains,20);                                         %绘制一个包含20柱的直方图来说明米粒大小分布情况

example 3
RGB=reshape(ones(64,1)*reshape(jet(64),1,192)[64,64,3]);
R=RGB(:,:,1);G=RGB(:,:,2);B=RGB(:,:,3);
subplot(221),imshow(R);subplot(222),imshow(G);subplot(223),imshow(B);subplot(224),imshow(RGB);

example 4 使用索引图像chess.met的颜色图map,通过抖动map中的颜色,产生RGB图像autumn.tif的索引图像
>>%-- 2014-3-1 22:50 --%
load chess;
RGB=inread('autumn.tif');
RGB=imread('autumn.tif');
subplot(121),imshow(RGB);
Y=dither(RGB,map);
subplot(122),imshow(Y,map);
%-- 2014-3-2 17:00 --%

example 5 将灰度图像转换成索引图像,颜色图分别为gray(128),gray(16)
>> I=imread('pout.tif');
>> [I1,map1]=gray2ind(I,128);
>> [I2,map2]=gray2ind(I,16);
>> subplot(131),imshow(I1,map1);subplot(132),imshow(I2,map2);subplot(133),imshow(I);
example 6 将一幅索引图trees.mat转换为灰度图
>>load trees
I=ind2gray(X,map);
subplot(121),imshow(X,map);subplot(122),imshow(I);

example 7 将RGB图像onion.png转换为灰度图像
>>RGB=imread('onion.png');
figure(1);imshow(RGB);figure(2);Y=rgb2gray(RGB);imshow(Y);

example 8 将RGB图像onion.png转换为索引图像
>>RGB=imread('onion.png');
figure(1);imshow(RGB);figure(2);Y=rgb2ind(RGB,128);imshow(Y);

example 9 将索引图像wmandril.mat转换为RGB图像
>>load wmandril;figure(1);imshow(X,map);I=ind2rgb(X,map);figure(2),imshow(I);

example 10 通过阀值法将索引图像转换为二值图像,阀值0.4
>>load trees;
BW=im2bw(X,map,0.4);figure(1);imshow(X,map);figure(2),imshow(BW);

example 11 将一幅灰度图像pout.tif转换为索引图像
>>I=imread('pout.tif');figure(1),imshow(I);X=grayslice(I,16);figure(2),imshow(X,hot(16));

example 12 将图像滤波后产生的矩阵转换为灰度图像
>>I=imread('trees.tif');figure(1),imshow(I);
J=filter2(fspecial('sobel'),I);K=mat2gray(J);figure(2),imshow(K);

example 13 过滤一个类为unit8的图像,然后将其显示为灰度图,并添加呀颜色条
>>I=imread('trees.tif');h=[121;000;-1-2-1];J=filter2(h,I);imshow(J,[]);colorbar;

example 14 并排显示两幅图像
[X1,map1]=imread('forest.tif');[X2,map2]=imread('trees.tif');subplot(121),imshow(X1,map1);subplot(122),imshow(X2,map2);
[X1,map1]=imread('forest.tif');[X2,map2]=imread('trees.tif');subplot(121),subimage(X1,map1);subplot(122),subimage(X2,map2);

(2)图像运算内容
example 1 将灰度图像使用灰度变换函数进行线性点运算
>>rice=imread('rice.png');I=double(rice);J=I*0.43+60;rice2=uint8(J);subplot(121),imshow(rice);subplot(122),imshow(rice2);

eaxmple 2 两幅图像叠加
>>I=imread('rice.png');J=imread('cameraman.tif');subplot(131),imshow(I);subplot(132),imshow(J);
K=imadd(I.J);subplot(133),imshow(K);

example 3 图像的减法运算
>>clear;close all;I=imread('rice.png');                     %读取和显示图像
background=imopen(I,strel('disk',15));                      %估计图像背景亮度
I2=imsubtract(I,background);                                %从原始图像中减去背景图像
subplot(121),imshow('rice.png');subplot(122),imshow(I2);

example 4 图像的乘法运算
>>I=imread('moon.tif');J=immultiply(I,1.2);subplot(121),imshow(I);subplot(122),imshow(J);

example 5 图像的除法运算
>>rice=imread('rice.png');background=imopen(rice,strel('disk',15));rice2=imsubtract(rice,background);
rice3=imdivide(rice,rice2);subplot(131),imshow(rice);subplot(132),imshow(rice2);subplot(133),imshow(rice3);

(3) 几何变换
example 1 使用不同的插值方法对图像进行放大
>>load woman2
subplot(2,2,1),imshow(X,map);
X1=imresize(X,2,'nearest');subplot(2,2,2),imshow(X1,[]);
X2=imresize(X,2,'bilinear');subplot(2,2,3),imshow(X2,[]);
X3=imresize(X,2,'bicubic');subplot(2,2,4),imshow(X3,[]);

example 2 图像旋转
>>I=imread('trees.tif');J=imrotate(I,35,'bilinear');subplot(121),imshow(I);subplot(122),imshow(J);

example 3 图像剪裁
>>I=imread('trees.tif');J=imcrop(I);imshow(J);

example 4 图像的滑动平均操作
>>I=imread('trees.tif');I2=colfilt(I,[5 5],'sliding','mean');figure(1),imshow(I);figure(2),imshow(I2,[]);

example 4 对输入图像处理,输出图像为每个像素领域的最大值
>>I=imread('trees.tif');figure(1),imshow(I);f=inline('ones(64,1)*mean(x)');
I2=colfilt(I,[8 8],'distinct',f);figure(2),imshow(I2,[]);

example 4 调用nlfilter函数进行滑动操作
>>I=imread('tire.tif');f=inline('max(x(:))');J=nlfilter(I,[3 3],f);
subplot(121),imshow(I);subplot(122),imshow(J);

example 5 图像块操作 计算图像8x8区域的局部标准差
>>I=imread('tire.tif');f=inline('uint8(round(std2(x)*ones(size(x))))');
I2=blkproc(I,[8 8],f);subplot(121),imshow(I);subplot(122),imshow(I2);

example 6 返回像素或像素集的数据值
>>imshow canoe.tif;vals=impixel  %在显示图像上点几个点,回车后显示数据值

example 7 强度描述图 improfile函数用于沿着图像一条直线路径或直线路径计算并绘制其强度值(灰度值)
>>imshow debyel.tif;improfile     %确定直线段后,按回车键,得到轨迹强度图
>>RGB=imread('peppers.png');figure(1),imshow(RGB);improfile

example 8 图像轮廓图
>>I=imread('rice.png');imshow(I);figure;imcontour(I);

example 9 图像柱状图
>>I=imread('rice.png');imhist(I,64);

( 4 )图像分析
example 1 灰度边缘检测
>>RGB=imread('peppers.png');figure(1);imshow(RGB);          %调入及显示RGB图
I=rgb2gray(RGB);figure(2),imshow(I);colorbar('horiz');      %RGB图转换为灰度图
ED=edge(I,'sobel',0.08);figure(3);imshow(ED);               %边缘检测,thresh值越小,显示细节越多

example 2 Sobel边界探测器和Canny边界探测器在图像分析中的应用
>>I=imread('rice.png');BW1=edge(I,'sobel');BW2=edge(I,'Canny');
figure(1),imshow(I);figure(2),imshow(BW1);figure(3),imshow(BW2);

( 5 )特定区域处理
example 1 根据指定的坐标选择一个六边形区域(选中区域为白色,其余的为黑色)
>>I=imread('eight.tif');c=[222 272 300 272 222 194];r=[21 21 75 121 121 75];
BW=roipoly(I,c,r);subplot(121),imshow(I);subplot(122),imshow(BW);

example 2 按灰度分割图像中的目标
>>I=imread('rice.png');BW=roicolor(I,128,255)                 %选择图像灰度范围在128和255之间的像素
subplot(121),imshow(I);subplot(122),imshow(BW);

example 3 特定区域滤波,对指定区域进行锐化滤波
>>I=imread('eight.tif');c=[222 272 300 272 222 194];r=[21 21 75 121 121 75];BW=roipoly(I,c,r);
h=fspecial('unsharp');     %指定滤波算子为'unsharp'
J=roifilt2(h,I,BW);subplot(121),imshow(I);subplot(122),imshow(J);

example 4 特定区域填充:填充指定的区域
>>I=imread('rice.png');c=[52 72 300 270 221 194];r=[71 21 75 121 121 75];
J=roifill(I,c,r);subplot(121),imshow(I);subplot(122),imshow(J);

( 6 )图像变换,傅里叶变换,
example 1 一幅图像的二维傅里叶变换
>>figure(1);load imdemos saturn2;                          %装入原始图像
imshow(saturn2);                                           %显示图像
figure(2);B=fftshift(fft2(saturn2));                       %进行傅里叶变换;
%fftshift(I)函数用于调整fft,fft2,fftn的输出结果。对于向量,fftshift(I),将I的左右两半交换位置;对于矩阵I,
 fftshift(I)将I的一,三象限和二四象限进行互换;对于高维矢量,fftshift(I)将矩阵各维的两半进行互换。
imshow(log(abs(B)),[]);colormap(jet(64)),colorbar;         %显示变换后的系数分布

example 2 利用freqz2函数得到的高斯滤波器的频率响应
>>h=fspecial('gaussian');freqz2(h)

example 3 一个计算魔方阵和一个矩阵的卷积
>>A=magic(3);B=ones(3);A(8 ,8)=0;B(8 ,8)=0;        %对A,B进行零填充,使之成为8X8矩阵
C=ifft2(fft2(A).*fft2(B));
C=C(1:5,1:5);                                    %抽取矩阵中的非零部分
C=real(C)                                        %去掉错误的,由四舍五入产生的虚部

example 4 图像特征识别:将包含字母a的图像与text.tif图像进行相关运算,也就是首先将字母a和图像text.tif进行傅里叶变换,然后利用快速卷积的方法,计算字母a和图像text.tif的卷积,提取卷积运算的峰值,图中所示的白色亮点,即得到在图像text.tif中字母a定位的结果
>>I=imread('text.tif');a=I(59:71:81:91);         %从图像中提取字母a的图像
subplot(221),imshow(I);subplot(222),imshow(a);
C=real(ifft2(fft2(I).*fft2(rot90(a,2),256,256)));subplot(223),imshow(C,[]);
thresh=max(C(:));                                %找到C中的最大值,选择一个略小于该数的数值作为阈值
subplot(224),imshow(C>thresh);                   %显示像素值超过阈值

example 5 离散余弦变换应用:把输入图像划分成8x8的图像块,计算它们的DCT系数,并且只保留64个DCT系数中的10个,然后对每个图像块利用这10个系数进行DCT反变换来重构图像
>>    
example 6
>>RGB=imread('autumn.tif');

转载于:https://www.cnblogs.com/pengzhi12345/p/11236745.html

MATLAB好玩的代码以及基础学习网站相关推荐

  1. java教学入门零基础学习网站,22年最新

    零基础自学JAVA,我首推这个网站只要你有一颗敢于学习的心,当然工欲善其事必先利其器,有了便利的工具,当然做什么都事半功倍.当下程序员就是高收入的代名词之一,说到编程,不得不提一下国外这个网站http ...

  2. 计算机应用基础学习网站,《计算机应用基础》学习手册.pdf

    <计算机应用基础>学习手册 一.课程介绍 1. 教学目标和教学内容 <计算机应用基础>作为大学新生入学后的第一门计算 机课程,主要教学目标是"普及计算机基础知识.培养 ...

  3. matlab数据归一化代码_深度学习amp;Matlab-LeNet实现图像分类

    明天准备用卷积神经网络处理分类问题,数据集大概有几万张图片,打算取其中的两类做一个简单分类.在这里先回顾一下以前在Matlab上利用LeNet对Mnist数据集做分类的代码. 本来是准备用Pytorc ...

  4. 将汉字转换成笔画代码_0基础学习五笔输入法之汉字的拆分

    未来的五笔高手们大家好,上篇文章我们讲述了五笔输入法的字型类型.我们先来回顾一下.五笔输入法字型分为三种类型,即左右型.上下型.杂合型.其中左右型与上下型比较好区分,杂合型相对来说不好区分. 大家以后 ...

  5. java基础学习网站

    最近在学习java基础,找的一些基础网站. https://blog.csdn.net/simplebam/article/details/68068128 https://www.yiibai.co ...

  6. 【A星算法】A星寻路算法详解(小白也可以看懂+C#代码+零基础学习A*)

    1.问题背景 在制作RPG游戏角色和NPC移动时,需要角色自动避开障碍物,到达终点 怎么快速找到一条到达终点的路径? 使用a星寻路算法 2.A星算法的思路 绿色:起点:红色:终点 :黑色:障碍物 新增 ...

  7. Aod-net代码相关基础学习

     PyTorch中文文档 The Python Imaging Library Handbook(PIL) numpy.asarray() Pyorch之numpy与torch之间相互转换 Torch ...

  8. Java基础学习网站收藏

    1.w3cschool菜鸟教程 http://m.w3cschool.cc/java/ 转载于:https://www.cnblogs.com/promise2mm/p/3729079.html

  9. 计算机应用基础学习网站,2017自学考试计算机应用基础模拟试题

    一.单项选择题***本大题共40小题,每小题1分,共40分***在每小题列出的四个选项中只有一个选项是符合题目要求的,请将正确选项前的字母填在题后的括号内. 1.一个完整的微型计算机系统包括*** * ...

最新文章

  1. Maven全局配置文件settings.xml 全解
  2. 【Scala】Scala-调用Java-集合
  3. IOS 其他 - 在真机调试的时候,将NSLog日志存入文件并保存到document目录
  4. Hadoop集群高可用及zookeeper+kafka组件搭建
  5. Java特性-Collection和Map
  6. jfinal框架中后台获取前端传递的参数
  7. js怎么设置z index.html,HTML5 Canvas set z-index
  8. win10系统同时安装python2和python3
  9. 设计模式之十一:抽象工厂模式(Abstract Factory)
  10. uiwebview 修改html,修改UIWebView加载的html文本属性
  11. 命令+mybatis-generator插件自己主动生成Mapper映射文件
  12. 大型企业***技术(cisco)
  13. VK1S68C中文资料
  14. Mybatis Configuration.xml中properties属性定义
  15. .NET下解析Json的方法
  16. 数据库、数据库系统、数据库管理系统三者的区别
  17. 链家全国房价数据分析 : 数据分析及可视化
  18. 定点补码加减法运算_定点加减法运算与溢出判断处理
  19. 计算机msvcp100.dll,msvcp100.dll丢失的解决方法
  20. Ubuntu系统搭建SU2计算环境

热门文章

  1. Linux入门开发: 从0开始搭建ubuntu系统环境(编写第一个C程序)
  2. Could not open Selected VM debug port (8700). Make sure you do not have another instance of DDMS
  3. 12306所有车次及时刻表的爬取上
  4. history 用法讲解
  5. JStorm与Storm源码分析(四)--均衡调度器,EvenScheduler
  6. 科研入门宝典(二):文献调研工作如何展开
  7. JS基础 Promise
  8. 阿拉丁小程序php面试题,阿拉丁:2018年1月至2月小程序榜单TOP 100
  9. MACos 苹果系统密码破解方法解决
  10. 利用Paddle OCR进行文字识别