当前位置:网站首页>matlab遍历图像、字符串数组等基本操作
matlab遍历图像、字符串数组等基本操作
2022-07-01 19:38:00 【明月醉窗台】
Matlab基本操作
1.遍历图像
1.1遍历文件夹图像
imgPath = 'E:/imageData/'; % 图像库路径
imgDir = dir([imgPath '*.jpg']); % 遍历所有jpg格式文件
for i = 1:length(imgDir) % 遍历结构体就可以一一处理图片了
img = imread([imgPath imgDir(i).name]); %读取每张图片
end
1.2遍历文件夹子目录内所有图像
imgDataPath = 'E:/imageData/';
imgDataDir = dir(imgDataPath); % 遍历所有文件
for i = 1:length(imgDataDir)
if(isequal(imgDataDir(i).name,'.')||... % 去除系统自带的两个隐文件夹
isequal(imgDataDir(i).name,'..')||...
~imgDataDir(i).isdir) % 去除遍历中不是文件夹的
continue;
end
imgDir = dir([imgDataPath imgDataDir(i).name '/*.jpg']);
for j =1:length(imgDir) % 遍历所有图片
img = imread([imgDataPath imgDataDir(i).name '/' imgDir(j).name]);
end
end
2.字符数组操作
以下代码实现对不同名称的图像进行高斯滤波
name={
'Lena','Monarch','House'};//字符串元胞数组
D={
'10','20','30','40','50','75','100'};
for i=1:length(name)
for j=1:length(D)
[name{
i},D{
j}]//读取内容用大括号{},若使用(),则输出还是元胞数组,不是字符串
path=['testimages\\',[name{
i},D{
j}],'.png'];//字符串拼接用[]
img=imread(path);
sigma=str2num(D{
j});
W = fspecial('gaussian',[sigma,sigma],1);
result = imfilter(img, W,'conv');
psnr=getPSNR(img,result);
imwrite(result,['testimages\\',[name{
i},D{
j}],'-psnr-',num2str(psnr),'.png']);
end
end
//计算峰值信噪比
function [psnr]=getPSNR(src,dst)
diff=src-dst;
MSE= sum(diff(:).*diff(:))/prod(size(src));
psnr = 10*log10(255^2/MSE);
end
3.寻找峰值
findpeaks 寻找峰值函数
pks = findpeaks(data)
[pks,locs] = findpeaks(data) ------pks 对应峰值,locs 对应峰值位数
[...] = findpeaks(data,'minpeakheight',mph)----mph 设定峰值的最小高度
[...] = findpeaks(data,'minpeakdistance',mpd)----mpd 设定两峰值间的最小间隔数
[...] = findpeaks(data,'threshold',th)
[...] = findpeaks(data,'npeaks',np)
[...] = findpeaks(data,'sortstr',str)
边栏推荐
- [C language] explain the usage of memset() function in detail
- PHP 读取ini或env类型配置
- 4. 对象映射 - Mapping.Mapstercover
- Keras machine translation practice
- leetcode刷题:二叉树02(二叉树的中序遍历)
- Past and present life of product modular design
- 2022年低压电工考试试题及答案
- Accelera Systems Initiative是一个独立的非营利组织
- RichView 文档中的 ITEM
- leetcode刷题:栈与队列05(逆波兰表达式求值)
猜你喜欢
随机推荐
随机头像大全,多分类带历史记录微信小程序源码_支持流量主
Iframe 父子页面通信
关于new Set( )还有哪些是你不知道的
新版图解网络PDF即将发布
8K HDR!|为 Chromium 实现 HEVC 硬解 - 原理/实测指南
leetcode刷题:栈与队列02(用队列实现栈)
latex如何打空格
Uniapp uses Tencent map to select points without window monitoring to return users' location information. How to deal with it
杰理之、产线装配环节【篇】
Principle of motion capture system
Keras machine translation practice
[multithreading] lock strategy
GCC编译
深度学习 常见的损失函数
UVM教程
Architect graduation summary
Swiftui 4 new features complete toggle and mixed toggle multiple binding components
tensorflow 张量做卷积,输入量与卷积核维度的理解
从20s优化到500ms,我用了这三招
Use Zadig to build a continuous delivery platform from 0 to 1









