美文网首页
matlab|图像增强

matlab|图像增强

作者: rivrui | 来源:发表于2019-05-24 23:15 被阅读0次

图像加减

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

◆ ◆ ◆ ◆ ◆

图片模糊

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

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

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
    end
end
​
new_img=uint8(new_img);
end

◆ ◆ ◆ ◆ ◆

图片锐化

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

举例,Reborts一阶锐化

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 
end
if 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
        
    end
end
new_img=uint8(new_img);
end

◆ ◆ ◆ ◆ ◆

为什么使用matlab?

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

为什么matlab写的这么差?

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

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

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

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

相关文章

网友评论

      本文标题:matlab|图像增强

      本文链接:https://www.haomeiwen.com/subject/beyozqtx.html