如何在matlab软件中对文件夹内的图片进行高斯模糊后在图片名称.jpg前加入_bulr后导出到第二个文件夹
时间: 2024-05-07 11:16:26 浏览: 187
您可以使用以下代码实现:
1. 先读取文件夹内的所有图片:
```
image_folder = 'your_folder_path';
filenames = dir(fullfile(image_folder, '*.jpg'));
```
2. 遍历每个图片,进行高斯模糊:
```
for i = 1:length(filenames)
image_name = filenames(i).name;
image_path = fullfile(image_folder, image_name);
img = imread(image_path);
blurred_img = imgaussfilt(img, 2); % 2为高斯模糊半径
```
3. 在图片名称前加入"_blur":
```
[~, name, ext] = fileparts(image_name);
new_name = [name, '_blur', ext];
```
4. 导出到第二个文件夹:
```
output_folder = 'your_output_folder_path';
imwrite(blurred_img, fullfile(output_folder, new_name));
```
完整代码如下:
```
image_folder = 'your_folder_path';
output_folder = 'your_output_folder_path';
filenames = dir(fullfile(image_folder, '*.jpg'));
for i = 1:length(filenames)
image_name = filenames(i).name;
image_path = fullfile(image_folder, image_name);
img = imread(image_path);
blurred_img = imgaussfilt(img, 2); % 2为高斯模糊半径
[~, name, ext] = fileparts(image_name);
new_name = [name, '_blur', ext];
imwrite(blurred_img, fullfile(output_folder, new_name));
end
```
希望能帮到您!
阅读全文