matlab 傅里叶画任何图

本文详细介绍了一种图像处理技术,通过使用Canny算法进行边缘检测,并应用快速傅立叶变换(FFT)对图像路径进行频域分析。该过程包括读取图像、灰度转换、尺寸调整、边缘检测及路径追踪,最后利用FFT分析路径特征。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

成品展示:https://www.bilibili.com/video/BV1M5411W7w8/
成品展示:https://www.bilibili.com/video/BV16A411v7ZV/

impath = '图片地址';
msizex = 300; %更改图片大小
msizey = 300;
img = imread(impath);
grey = rgb2gray(img);
resizeGrey = imresize(grey, [msizex, msizey]);
eg = edge(resizeGrey, 'canny');
[x, y] = find(eg);

global Path G;
Path = [];
G = rot90(eg, 3) ;
XSN = struct('path', {});
for i = 1:msizex
    for j = 1:msizey
        if G(i, j) ~= 0
            dfs(i, j);
%             Path
            XSN(end + 1).path = Path;
            Path = [];
        end
    end
end

imshow(rot90(eg, 3))
imshow(eg)

XnSet = struct('Xn', {}, 'XnSum', {});
for i = 1:length(XSN)
    tmp = fft(XSN(i).path);
    A = exp(2i * pi .* ([0:length(tmp) - 1]' * [0:length(tmp) - 1]) ./ length(tmp)) ./ length(tmp);
    for j = 1:length(A(:, 1))
        A(j, :) = tmp .* A(j, :);
    end
    XnSet(end + 1).Xn = A;
    XnSet(end).XnSum = cumsum(A, 2);
end


figure(1)
for i = 1:length(XnSet)
    for j=1:1:length(XnSet(i).XnSum)
        clf
        hold on
        plot(XnSet(i).XnSum(j, :)); 
        
        if i > 1
             for k = 1:i - 1
                plot(XnSet(k).XnSum(:,end),'-r')
            end
        end
       

        plot(XnSet(i).XnSum(1:j,end),'-r')
        hold off
 
        xlim([0,500]);ylim([0,500])%画框大小
        pause(0.01)
    
    end
end


function [] = dfs(x, y)
    global Path G;
    dx = [0, 0, 1, 1, 1, -1, -1, -1];
    dy = [1, -1, 0, -1, 1, 0, 1, -1];
    G(x, y) = 0;
    Path(end + 1) = x + y * 1i;
    for i = 1:8
        if G(x + dx(i), y + dy(i)) ~= 0
            dfs(x + dx(i), y + dy(i));
            Path(end + 1) = x + y * 1i;
        end
        
    end
end
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值