《laplacian边缘检测算子matlab实现》由会员分享,可在线阅读,更多相关《laplacian边缘检测算子matlab实现(2页珍藏版)》请在金锄头文库上搜索。
1、%本代码是拉普拉斯算子的matlab实现过程%Laplacian为laplacian的子函数,laplacian为拉普拉斯增强函数的调用接口function R = laplacian( I )%I为要进行拉普拉斯增强的图像,R为得到的增强图像length_x, length_y = size(I); R = zeros(length_x, length_y); for i = 2 : length_x - 1 for j = 2 : length_y - 1 templet = I(i-1 : i+1, j-1 : j+1); templet = double(templet); temp
2、= Laplacian(templet); R(i, j) = round(temp); endend min_R = min(R(:); if min_R 0 R = R - min_R;end% R = R * (255/max_R);%这一句一般不用,因为图像中最大的灰度值附近可能只有个别点,这样会使图像灰度范围变窄R = uint8(R);end function newPixel = Laplacian( templet )% L4 = 0, -1, 0; -1, 5, -1; 0, -1, 0; % laplacian算子%L4 = -1, -1, -1; -1, 11, -1; -1, -1, -1; % laplacian算子% temp1 = templet(1, :) * L4(:, 1);temp2 = templet(2, :) * L4(:, 2);temp3 = templet(3, :) * L4(:, 3); newPixel = temp1 + temp2 + temp3;end