当前位置:网站首页>Matlab traverses images, string arrays and other basic operations
Matlab traverses images, string arrays and other basic operations
2022-07-01 22:24:00 【Bright moon drunk windowsill】
Matlab Basic operation
1. Traversal image
1.1 Traverse the folder image
imgPath = 'E:/imageData/'; % Image library path
imgDir = dir([imgPath '*.jpg']); % Traverse all of jpg Format file
for i = 1:length(imgDir) % You can process the pictures one by one by traversing the structure
img = imread([imgPath imgDir(i).name]); % Read each picture
end
1.2 Traverse all images in the folder subdirectory
imgDataPath = 'E:/imageData/';
imgDataDir = dir(imgDataPath); % Traverse all files
for i = 1:length(imgDataDir)
if(isequal(imgDataDir(i).name,'.')||... % Remove the two hidden folders provided by the system
isequal(imgDataDir(i).name,'..')||...
~imgDataDir(i).isdir) % Remove those that are not folders in traversal
continue;
end
imgDir = dir([imgDataPath imgDataDir(i).name '/*.jpg']);
for j =1:length(imgDir) % Go through all the pictures
img = imread([imgDataPath imgDataDir(i).name '/' imgDir(j).name]);
end
end
2. Character array operations
The following code implements Gaussian filtering for images with different names
name={
'Lena','Monarch','House'};// String cell array
D={
'10','20','30','40','50','75','100'};
for i=1:length(name)
for j=1:length(D)
[name{
i},D{
j}]// Read the content with braces {}, If you use (), Then the output is still a cell array , It's not a string
path=['testimages\\',[name{
i},D{
j}],'.png'];// String splicing []
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
// Calculate the peak signal-to-noise ratio
function [psnr]=getPSNR(src,dst)
diff=src-dst;
MSE= sum(diff(:).*diff(:))/prod(size(src));
psnr = 10*log10(255^2/MSE);
end
3. Looking for peaks
findpeaks Find the peak function
pks = findpeaks(data)
[pks,locs] = findpeaks(data) ------pks Corresponding peak ,locs Corresponding peak digits
[...] = findpeaks(data,'minpeakheight',mph)----mph Set the minimum height of the peak
[...] = findpeaks(data,'minpeakdistance',mpd)----mpd Set the minimum interval between two peaks
[...] = findpeaks(data,'threshold',th)
[...] = findpeaks(data,'npeaks',np)
[...] = findpeaks(data,'sortstr',str)
边栏推荐
- Electron学习(三)之简单交互操作
- 【单体】流辰信息I-BPSv3服务器推荐配置
- Four methods of JS array splicing [easy to understand]
- "The silk road is in its youth and looks at Fujian" is in the hot collection of works in the Fujian foreign youth short video competition
- Internet of things RFID, etc
- 最近公共祖先(LCA)在线做法
- Case of camera opening by tour
- PHP reflective XSS, reflective XSS test and repair
- Introduction and download of the latest version of airserver2022
- Manually implement function isinstanceof (child, parent)
猜你喜欢

Icml2022 | interventional contrastive learning based on meta semantic regularization

pytest合集(2)— pytest运行方式

Flume面试题

BlocProvider 为什么感觉和 Provider 很相似?

MySQL系列之事务日志Redo log学习笔记

杰理之、产线装配环节【篇】

九章云极DataCanvas公司蝉联中国机器学习平台市场TOP 3

【深度学习】利用深度学习监控女朋友的微信聊天?

【直播回顾】战码先锋首期8节直播完美落幕,下期敬请期待!
![[intelligent QBD risk assessment tool] Shanghai daoning brings you leanqbd introduction, trial and tutorial](/img/ac/655fd534ef7ab9d991d8fe1c884853.png)
[intelligent QBD risk assessment tool] Shanghai daoning brings you leanqbd introduction, trial and tutorial
随机推荐
MySQL series transaction log redo log learning notes
[monomer] recommended configuration of streaming information i-bpsv3 server
A debugging to understand the slot mechanism of redis cluster
Significance and measures of security encryption of industrial control equipment
Classify boost libraries by function
函数基本学习之一
String type conversion BigDecimal, date type
Can I choose to open an account for stock trading on flush? Is it safe?
Training on the device with MIT | 256Kb memory
ICML2022 | 基于元语义正则化的介入性对比学习
Electron学习(三)之简单交互操作
十三届蓝桥杯B组国赛
Why does blocprovider feel similar to provider?
基于LSTM模型实现新闻分类
【单体】流辰信息I-BPSv3服务器推荐配置
打出三位数的所有水仙花数「建议收藏」
AirServer2022最新版功能介绍及下载
杰理之关于长按开机检测抬起问题【篇】
Getting started with the lockust series
Qtreeview+qabstractitemmodel custom model: the third of a series of tutorials [easy to understand]