• 一个matlab数字图像处理程序的解释


    clc;                                                   %clc是清除command window里的内容
    clear all;                                             %clear是清除workspace里的变量
    close all;                                             %close all来关闭所有已经打开的图像窗口
    image_ori = imread('skeleton_orig.bmp');               %读取图像数据
    image_ori = rgb2gray(image_ori);                       % 将rgb模式转换成灰度图
    figure;                                                %画图
    subplot(2,4,1);                                        %把区域分成2行4列,并把图像显示到第一个
    imshow(image_ori);                                     %显示图像
    title('a.original image');                             %显示标题
    image_ext = [zeros(1,500);image_ori;zeros(1,500)]';    %分别在上下两边加一行,并转置
    image_ext = [zeros(1,802);image_ext;zeros(1,802);]';   %分别在左右两边加一列,并转置
    image_double = im2double(image_ext);                   %将imdata_add转换成双精度
    
    % lapa_modelace Operating 
    lapa_mode = [-1,-1,-1;-1,8,-1;-1,-1,-1];                %拉普拉斯变换用模板[-1,-1,-1;-1,8,-1;-1,-1,-1]; 
    lapa_mode = lapa_mode(:);                               %转换成列矩阵
    for x = 2:1:801
        for y = 2:1:501
        A =image_double([x-1:x+1],[y-1:y+1]);               %从image_double中以(x,y)为中心取出一个3*3的矩阵 
        image_lapa(x-1,y-1) = lapa_mode'*A(:);              %将取出的矩阵与模板进行拉普拉斯变换取得的值放在image_lapa的(x-1,y-1)位置
        end
    end
    subplot(2,4,2);
    imshow(image_lapa);
    title('b.lapalace image');
    subplot(2,4,3);
    
    %Sharpening Operating
    image_ab_sha = image_lapa+im2double(image_ori);           
    imshow(image_ab_sha);
    title('c.a+b sharpening image');
    
    %Grads Operating
    sobel_mode_1= [-1,-2,-1;0,0,0;1,2,1];                     %定义梯度处理的一个掩膜
    sobel_mode_1= sobel_mode_1(:);
    sobel_mode_2 = [-1,0,1;-2,0,2;-1,0,1];                    %定义梯度处理的另一个掩膜
    sobel_mode_2 = sobel_mode_2(:);
    for x = 2:1:801
        for y = 2:1:501
        A =image_double([x-1:x+1],[y-1:y+1]); 
        mid_1(x-1,y-1) = sobel_mode_1'*A(:); 
        mid_2(x-1,y-1) = sobel_mode_2'*A(:);
        end
    end
    image_grad = abs(mid_1)+abs(mid_2);                        %对gx、gy绝对值化,然后求和
    subplot(2,4,4);
    imshow(image_grad);
    title('d.grads image');
    
    %Smoothing Operating
    Mxy_Ext = [zeros(2,500);image_grad;zeros(2,500)];           %分别在上下两边加两行
    Mxy_Ext = [zeros(2,804);Mxy_Ext';zeros(2,804)]';            %先将Mxy_Ext转置,然后分别在左右两边加一列,最后将所得结果再转置
    Linear_smooth = ones(5,5);                                  %创建一个5*5矩阵,初始值全是1
    Linear_smooth = Linear_smooth(:);                           %将矩阵Linear_smooth转换成列矩阵
    for x = 3:1:802                                             %大循环,x从3--802,步进是1
        for y = 3:1:502                                         %小循环,y从3--502,步进是1
            A = Mxy_Ext([x-2:x+2],[y-2:y+2]);                   %以Emx_Ext(x,y)为中心,截取5*5矩阵复制到A中
            image_smooth(x-2,y-2) = Linear_smooth'*A(:);         %将获取的矩阵值各个值求和然后放在新矩阵image_smooth的(x-2,y-2)位置
        end
    end
    image_smooth = image_smooth/25;                             %求平均值
    subplot(2,4,5);                                             %把区域分成1行4列,并把图像显示到第一个
    imshow(image_smooth);                                       %显示图像
    title('e.smoothing image');                                 %显示标题
    
    %Masking Operating 
    image_mask = image_ab_sha.*image_smooth;                    %点乘
    subplot(2,4,6);
    imshow(image_mask);
    title('f.Masking image');
    
    %Sharpening Operating
    image_af_sha = im2double(image_ori) + image_mask;
    subplot(2,4,7);
    imshow(image_af_sha);
    title('g.a+f sharpening image');
    
    %Exponential  Transform
    image_fin = image_af_sha.^0.5;                              %幂律变换 
    subplot(2,4,8);
    imshow(image_fin);
    title('h.final result');
  • 相关阅读:
    IE6下,设置了domain,导致target指向iframe时,无法打开链接的问题及解决
    contains和compareDocumentPosition 方法来确定是否HTML节点间的关系
    xCode4.2中导入OpenFlow库到项目中出现编译警告warning: Semantic Issue: Writable atomic property
    NSXMLParser具体解析xml的应用详解
    CoCoa编程中视图控制器与视图类(一)
    CoCoa编程中视图控制器与视图类(二)
    关于值传递(高手请无视)
    程序员人生之DAN疼篇
    jquery杂谈jquery选择符
    怎么样把 swf格式 转换为flv格式
  • 原文地址:https://www.cnblogs.com/amanlikethis/p/3423445.html
Copyright © 2020-2023  润新知