联系QQ:

2181264433

新闻资讯
联系我们
联系:张女士
微信:扫一扫右侧二维码
QQ :2181264433
邮箱:2181264433@qq.com
地址:浙江省-嘉兴市-南湖区
网址:www.mhslogic.com
您当前位置:首页 > 国内资讯 > 正文国内资讯
MATLAB代做|FPGA代做|simulink代做——经Marr算子处理后的图像
添加时间:2020-8-12 来源:本站整理
function [out_args]=marr_laplacian(fn,choice)
bmparr=mat2gray(double(imread(fn)),[0,255]);
bmparr=rgb2gray(bmparr);

[xlen ylen]=size(bmparr);
workarr=zeros(xlen,ylen);
subplot(1,2,1);
figure(1);
imshow(bmparr);
title('原图像');
switch choice
    case 'laplacian'
        h=1/8*[ -2 1  -2; 1  4 1;-2 1  -2];
        diff2=zeros(xlen,ylen);
        dt=1;
        for i=1:xlen
            for j=1:ylen
                for k=1:3
                    for l=1:3
                        xp=i-k+1+dt;
                        yp=j-l+1+dt;
                        if((xp>=1)&&(xp<=xlen)&&(yp>=1)&&(yp<=ylen)) diff2(i,j)=diff2(i,j)+h(k,l)*double(bmparr(xp,yp)); end
                    end
                end
            end
        end
        
        th=0.75*mean2(abs(diff2(2:xlen-1,2:ylen-1)));
        for i=2:xlen-1
            for j=2:ylen-1
                if(diff2(i,j)<0)
                    if((diff2(i,j-1)>0)&&(diff2(i,j-1)-diff2(i,j)>th)) workarr(i,j)=1; end
                    if((diff2(i,j+1)>0)&&(diff2(i,j+1)-diff2(i,j)>th)) workarr(i,j)=1; end
                    if((diff2(i-1,j)>0)&&(diff2(i-1,j)-diff2(i,j)>th)) workarr(i,j)=1; end
                    if((diff2(i+1,j)>0)&&(diff2(i+1,j)-diff2(i,j)>th)) workarr(i,j)=1; end
                elseif(diff2(i,j)==0)
                    if((diff2(i,j-1)<0)&&(diff2(i,j+1)>0)&&(diff2(i,j+1)-diff2(i,j-1)>2*th)) workarr(i,j)=1; end
                    if((diff2(i,j-1)>0)&&(diff2(i,j+1)<0)&&(diff2(i,j-1)-diff2(i,j+1)>2*th)) workarr(i,j)=1; end
                    if((diff2(i-1,j)<0)&&(diff2(i+1,j)>0)&&(diff2(i+1,j)-diff2(i-1,j)>2*th)) workarr(i,j)=1; end
                    if((diff2(i-1,j)>0)&&(diff2(i+1,j)<0)&&(diff2(i-1,j)-diff2(i+1,j)>2*th)) workarr(i,j)=1; end
                end
            end
        end
        workarr=mat2gray(workarr);
        subplot(1,2,2);
        figure(2);
        imshow(workarr);
        title('经laplacian算子处理后的图像');
    case 'marr'
        sigma=2;
        m=ceil(sigma*3)*2+1;
        h=fspecial('log',m,sigma);
    %    h=h-sum(h(:))/(m^2);
        diff2=zeros(xlen,ylen);
        dt=ceil((m-1)/2);
        for i=1:xlen
            for j=1:ylen
                for k=1:m
                    for l=1:m
                        xp=i-k+1+dt;
                        yp=j-l+1+dt;
                        if((xp>=1)&&(xp<=xlen)&&(yp>=1)&&(yp<=ylen)) diff2(i,j)=diff2(i,j)+h(k,l)*double(bmparr(xp,yp)); end
                    end
                end
            end
        end
        th=0.75*mean2(abs(diff2(2:xlen-1,2:ylen-1)));
        for i=2:xlen-1
            for j=2:ylen-1
                if(diff2(i,j)<0)
                    if((diff2(i,j-1)>0)&&(diff2(i,j-1)-diff2(i,j)>th)) workarr(i,j)=1; end
                    if((diff2(i,j+1)>0)&&(diff2(i,j+1)-diff2(i,j)>th)) workarr(i,j)=1; end
                    if((diff2(i-1,j)>0)&&(diff2(i-1,j)-diff2(i,j)>th)) workarr(i,j)=1; end
                    if((diff2(i+1,j)>0)&&(diff2(i+1,j)-diff2(i,j)>th)) workarr(i,j)=1; end
                elseif(diff2(i,j)==0)
                    if((diff2(i,j-1)<0)&&(diff2(i,j+1)>0)&&(diff2(i,j+1)-diff2(i,j-1)>2*th)) workarr(i,j)=1; end
                    if((diff2(i,j-1)>0)&&(diff2(i,j+1)<0)&&(diff2(i,j-1)-diff2(i,j+1)>2*th)) workarr(i,j)=1; end
                    if((diff2(i-1,j)<0)&&(diff2(i+1,j)>0)&&(diff2(i+1,j)-diff2(i-1,j)>2*th)) workarr(i,j)=1; end
                    if((diff2(i-1,j)>0)&&(diff2(i+1,j)<0)&&(diff2(i-1,j)-diff2(i+1,j)>2*th)) workarr(i,j)=1; end
                end
            end
        end
        workarr=mat2gray(workarr);
        subplot(1,2,2);
        figure(3);
        imshow(workarr);
        title('经Marr算子处理后的图像');

end


联系:张女士

QQ :2181264433

微信:lovemike121

邮箱:2181264433@qq.com

网站:http://www.mhslogic.com/

------------------------------------------------------------------------------------------------

交易可直接通过淘宝店铺


(可直接通过旺旺与技术员联系)




https://shop185632181.taobao.com/?spm=2013.1.w5001-22653403434.6.27f92e0a6xR1sB&scene=taobao_shop

扫一扫,关注我们