前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >matlab | 图像增强-模板处理

matlab | 图像增强-模板处理

作者头像
福贵
发布2019-05-05 14:38:19
8750
发布2019-05-05 14:38:19
举报
文章被收录于专栏:合集

图像加减

对图片的像素值进行加减,在图片相加的时候为避免出现大于255的值,可以对两者图片进行加权处理。图片相减的时候,差值小于0时可以直接取0,当然也可以取绝对值。

◆ ◆ ◆ ◆ ◆

图片模糊

常见的有均值滤波,加权滤波和中值滤波。模板大小会直接影响处理效果,对于图片边缘采取不处理或者新的模板进行处理。

举例,中值滤波,边缘不处理

代码语言:javascript
复制
function new_img = mid_smooth(img_path,template)%MEAN_SMOOTH 此处显示有关此函数的摘要%   此处显示详细说明img=imread(img_path);radius=floor(template/2);shape=size(img);new_img=img;
for tunnel=1:ndims(img)    for height =radius+1:shape(1)-radius        for width =radius+1:shape(2) - radius            new_img(height, width,tunnel)=0;            pixel=zeros(template,template);            for i = (-radius):radius                for j = (-radius):radius                    pixel((i+radius+1),(j+radius+1)) = img(height + i, width + j,tunnel);                end            end            pixel=sort(pixel,2);            new_img(height, width,tunnel)=pixel(floor(template^2/2));        end    endend
new_img=uint8(new_img);end

◆ ◆ ◆ ◆ ◆

图片锐化

图片锐化主要就是一阶锐化和二阶锐化。除了基本锐化,一阶锐化一般还有Sobel和Reborts算子一类,而二阶锐化则是Laplacian算子。继续细分则在于模板的大小,是否添加对角等。

举例,Reborts一阶锐化

代码语言:javascript
复制
function new_img = reborts_first_sharpen(img_path,dire)%FIRST_SHARPEN 此处显示有关此函数的摘要%   此处显示详细说明img=imread(img_path);new_img=img;shape=size(img);if dire==1    for tunnel=1:ndims(img)        for height=1:shape(1)-1            for width=1:shape(2)-1                new_img(height,width,tunnel)=img(height,width,tunnel)-img(height+1,width+1,tunnel);            end        end    end endif dire==2    for tunnel=1:ndims(img)        for height=1:shape(1)-1            for width=1:shape(2)-1                new_img(height,width,tunnel)=img(height+1,width,tunnel)-img(height,width+1,tunnel);            end        end            endendnew_img=uint8(new_img);end

◆ ◆ ◆ ◆ ◆

为什么使用matlab?

程序需要GUI,Python的tkinter库让我放弃。

为什么matlab写的这么差?

为了GUI才学的,差也正常。

为什么我看不懂写的什么?

没关系,反正写了是给自己看的,或者已经懂了的人看的。

吐槽:微信公众号对日语编码不友好。

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2019-04-06,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 Python与MySQL 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档