【发布时间】:2023-03-08 03:30:01
【问题描述】:
我想在 matlab 中编写一个代码,它将接受来自隐式给定目录的图像,并在移动中对每个图像应用 Sobel 边缘检测算法。请帮忙
【问题讨论】:
标签: matlab image-processing edge-detection
我想在 matlab 中编写一个代码,它将接受来自隐式给定目录的图像,并在移动中对每个图像应用 Sobel 边缘检测算法。请帮忙
【问题讨论】:
标签: matlab image-processing edge-detection
MATLAB 中的 Sobel 边缘检测仅适用于灰度图像,因此您需要将任何图像转换为灰度表示。如果您在桌面上有一个文件夹,其中所有图像都驻留,那么下面的 sn-p 代码可以满足您的需求。
dirname = '~/Desktop/imgs/';
files = dir([dirname, '*.png']);
files = {files.name}';
for ifile = 1:numel(files)
imfile = [dirname, files{ifile}];
im = imread(imfile); % Read the image file
img = rgb2gray(im); % Convert to grayscale
ime = edge(img, 'sobel'); % Edge detection
figure(1)
imshow(ime);
outname = ['edge_', files{ifile}];
imwrite(ime, outname);
end
希望对您有所帮助。
【讨论】: