做完第一周Matlab作业,深感MatLab之强大。(都第几周了,才做第一周作业…)
不在上图像处理这门课的同学,也可以试试在Matlab敲这些代码哦~ 用Matlab P图可有意思呢~

第一周是粗略地体验图像处理,先把题目要求贴上来:
Write a computer program capable of reducing the number of intensity levels in an image from 256 to 2, in integer powers of 2. The desired number of intensity levels needs to be a variable input to your program.
Using any programming language you feel comfortable with (it is though recommended to use the provided free Matlab), load an image and then perform a simple spatial 3x3 average of image pixels. In other words, replace the value of every pixel by the average of the values in its 3x3 neighborhood. If the pixel is located at (0,0), this means averaging the values of the pixels at the positions (-1,1), (0,1), (1,1), (-1,0), (0,0), (1,0), (-1,-1), (0,-1), and (1,-1). Be careful with pixels at the image boundaries. Repeat the process for a 10x10 neighborhood and again for a 20x20 neighborhood. Observe what happens to the image (we will discuss this in more details in the very near future, about week 3).
Rotate the image by 45 and 90 degrees (Matlab provides simple command lines for doing this).
For every 3×3 block of the image (without overlapping), replace all corresponding 9 pixels by their average. This operation simulates reducing the image spatial resolution. Repeat this for 5×5 blocks and 7×7 blocks. If you are using Matlab, investigate simple command lines to do this important operation.

=======================

实验用图

图像处理的第一件事,是找张图片。
盗用一张自诩为艺术家的好基友拍的照片,这是我们在拉萨约会时拍的.()
图片版权归好基友,转图请注明出处。

所谓的牦牛肉牛排,好韧的肉,要用好大力气吃… 还是肉牛做的牛排比较靠谱。

=======================

用得着的Matlab说明文档

blockproc
http://www.mathworks.cn/cn/help/images/ref/blockproc.html
Performing Distinct Block Operations
http://www.mathworks.cn/cn/help/images/performing-distinct-block-operations.html
Performing Sliding Neighborhood Operations
http://www.mathworks.cn/cn/help/images/performing-sliding-neighborhood-operations.html
nlfilter
http://www.mathworks.cn/cn/help/images/ref/nlfilter.html
Local Functions
http://www.mathworks.cn/cn/help/matlab/matlab_prog/local-functions.html
idivide
http://www.mathworks.cn/cn/help/matlab/ref/idivide.html
Loop Control Statements
http://www.mathworks.cn/cn/help/matlab/matlab_prog/loop-control-statements.html
Matrix Indexing
http://www.mathworks.cn/cn/help/matlab/math/matrix-indexing.html
mean
http://www.mathworks.cn/cn/help/matlab/ref/mean.html
mean2
http://www.mathworks.cn/cn/help/images/ref/mean2.html
sum
http://www.mathworks.cn/cn/help/matlab/ref/sum.html
imrotate
http://www.mathworks.cn/cn/help/images/ref/imrotate.html

=======================

读取图片,转成灰度图

origin_im = imread('F:/dip/goof.jpg'); %读取图片,要修改图片路径为自己的图片才能执行哦
gray_im = rgb2gray(origin_im); %转成灰度图

Week1所需要的处理,在灰度图中比较好操作,所以先把图片转换成灰度。(马上没有食欲了…)

=======================

逐次改变intensity

我这里用了最粗暴的方法,教授表示比较好的方法是Error Diffusion,求补充~

image_size = size(gray_im);
out_gif = uint8( zeros( image_size(1),image_size(2),1,8));
for n = 1:8intensity = 2^n;intensity_reduced = ( gray_im / ( 256/(intensity-1) ) ) * ( 256/(intensity-1) );out_gif(:,:,1,9-n) = intensity_reduced;
end
imwrite(out_gif,'F:\dip\goof_intensity.gif','LoopCount',Inf);

Intensity逐渐减少,就是这个效果的~

=======================

平滑处理(Overlap average)

平滑处理是常用的处理技术,可以清除一些白噪声。
但如果处理得太过分,就会像下面第三幅图那样…嗯。

=======================

fun = @(x) uint8(mean2(x(:)));
overlap_avg_3 = nlfilter(gray_im,[3 3],fun);
overlap_avg_10 = nlfilter(gray_im,[10 10],fun);
overlap_avg_20 = nlfilter(gray_im,[20 20],fun);
figure,imshow(gray_im),figure,imshow(overlap_avg_3),figure,imshow(overlap_avg_10),figure,imshow(overlap_avg_20);



没戴眼镜的效果。

不难发现,第三幅图像有明显的黑边,那是因为处理边缘像素的时候,函数默认将边界外的像素值设为0.

=======================

图像旋转(Rotation)

r45 = imrotate(gray_im,45);
r90 = imrotate(gray_im,90);
figure,imshow(r45),figure,imshow(r90);


=======================

Non-overlap average

咦,这是打码的技术?

=======================

fun = @(block_struct) uint8( mean2(block_struct.data(:))  * ones(block_struct.blockSize) );
block_avg_3 = blockproc(gray_im,[3 3],fun);
block_avg_5 = blockproc(gray_im,[5 5],fun);
block_avg_7 = blockproc(gray_im,[7 7],fun);
figure,imshow(gray_im),figure,imshow(block_avg_3),figure,imshow(block_avg_5),figure,imshow(block_avg_7);



马赛克的效果。

第一周的Matlab作业就到这里啦~
赶紧第二周的…

【MATLAB】P图神器,初露锋芒:第一周作业相关推荐

  1. matlab p图,【MATLAB】P图神器,初露锋芒:第一周作业(剧透)

    做完第一周Matlab作业,深感MatLab之强大.(都第几周了,才做第一周作业...) 不在上图像处理这门课的同学,也可以试试在Matlab敲这些代码哦~ 用Matlab P图可有意思呢~ Writ ...

  2. RT-thread 柿饼UI demo(文本浏览+电子相册) ---- 暨柿饼入门课第一周作业附加题

    一.题目要求 完成下图的应用制作,范进中举复制群文件内的范进中举.txt内的内容. 二.实现过程 2.1.整体思路 整体的框架是在一个page中放入三个button控件(负责控制三个显示界面的切换)和 ...

  3. 【中文】【吴恩达课后编程作业】Course 5 - 序列模型 - 第一周作业

    [中文][吴恩达课后编程作业]Course 5 - 序列模型 - 第一周作业 - 搭建循环神经网络及其应用 上一篇:[课程5 - 第一周测验]※※※※※ [回到目录]※※※※※下一篇:[课程5 - 第 ...

  4. 2019-2020-1 1823《程序设计与数据结构》第一周作业总结

    作业地址 第一周作业:https://edu.cnblogs.com/campus/besti/2019-2020-1-1823-PDDS/homework/3466 提交情况如图: 共7人没提交,还 ...

  5. 【中文】【吴恩达课后编程作业】Course 2 - 改善深层神经网络 - 第一周作业(123)

    [中文][吴恩达课后编程作业]Course 2 - 改善深层神经网络 - 第一周作业(1&2&3) - 初始化.正则化.梯度校验 上一篇:[课程2 - 第一周测验]※※※※※ [回到目 ...

  6. Boolan第一周笔记(二)对于第一周作业的一点总结

    本文主要总结下面的问题: 1.为什么这周的作业里面,创建数组的时候使用堆内存更好: 2.指针指向不同类型走的步数不同. 第一周作业内容如下,题目来自Boolan: 为Date类实现如下成员: 1. 构 ...

  7. 输出结果为16的python表达式_第一周作业(rayco)

    rayco 第一周作业 第一次-课后习题 a = 10 b = 3 c = a/b-a print(c, type(c)) c = a/b*a print(c, type(c)) c = 0.1*a/ ...

  8. 吴恩达 02.改善深层神经网络:超参数调试、正则化以及优化 第一周作业

    Initialization Welcome to the first assignment of "Improving Deep Neural Networks". Traini ...

  9. 2017-2018-2 《密码与安全新技术》第一周作业

    2017-2018-2 <密码与安全新技术>第一周作业 课程:<密码与安全新技术> 班级:2017级92班 学号:20179225 上课教师:谢四江 上课日期:2018年3月1 ...

最新文章

  1. 【CI3.1】CI框架简单使用方法
  2. 机器学习算法库scikit-learn的安装
  3. MongoDB ( 五 )高级_索引
  4. 你知道到底什么是Unikernel吗
  5. python的aes的ecb加密_AES ECB PKCS5/PKCS7 加密 python实现 支持中文
  6. DM6467T开发板领航——开发环境
  7. 数值的八进制、十六进制表示,及以二进制进行显示
  8. 凌云ERP解析企业如何选择合适的ERP系统
  9. Origin 在新打开的工作区添加列
  10. yacc c语言语法分析,编译原理实践--语法分析程序的自动生成工具YACC.PPT
  11. matlab实现机器学习算法-回归分析
  12. 【Java架构师入门到精通】java分布式架构有哪些技术
  13. Mixly Aduino 超声波~蜂鸣器
  14. 微信小程序开发-云数据库添加及获取显示
  15. Cfree5可以JAVA_无法使用free()释放内存
  16. 国产首发:上海川土微电子数字接口电源数字隔离芯片模拟芯片领导者
  17. Web登录小案例(含验证码登录)
  18. php mysql 性能测试工具_MySQL_Sysbench多线程性能测试工具,最近用sysbench进行了较多的性 - phpStudy...
  19. 百度大脑营业执照识别使用攻略
  20. 微信小程序利用腾讯云IM发送语音 + 图片

热门文章

  1. dpkg-checkbuilddeps: error: Unmet build dependencies: libtest-mockmodule-perl
  2. 说说JDBC 操作数据库的步骤?
  3. 联想拯救者Y7000系列黑苹果MacOS 12.3.1 Monterey详细安装教程记录
  4. i5-8500 搭配 RTX3090 算不算奇葩
  5. 如何在OUTLOOK签名中自动加入日期
  6. centOS7 防火墙关闭 远程端口无法访问问题
  7. STM32蓝牙小车以及PWM调速
  8. 天翼云对象存储Java对接(经典版 Ⅱ型)
  9. 我的世界服务器连接协议,go-mc: Minecraft(我的世界)各种协议的Go实现
  10. wps里有project吗_甘特图是什么?-如何用WPS表格做甘特图