当前位置:网站首页>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)
边栏推荐
- "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
- 基于K-means的用户画像聚类模型
- 【深度学习】利用深度学习监控女朋友的微信聊天?
- 微信小程序,连续播放多段视频。合成一个视频的样子,自定义视频进度条
- 杰理之关于长按开机检测抬起问题【篇】
- PCB线路板塞孔工艺的那些事儿~
- 同花顺股票开户选哪个券商好手机开户是安全么?
- Burpsuite simple packet capturing tutorial [easy to understand]
- 上半年暂停考试要补考?包含监理工程师、建筑师等十项考试
- CNN convolution neural network principle explanation + image recognition application (with source code) [easy to understand]
猜你喜欢

Aidl basic use

JS how to get a list of elements in a collection object

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

二叉树的基本操作

Talking from mlperf: how to lead the next wave of AI accelerator

基于三维GIS的不动产管理应用
![[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

BlocProvider 为什么感觉和 Provider 很相似?
![比较版本号[双指针截取自己想要的字串]](/img/19/4f858ffdc1281d6b8b18a996467f10.png)
比较版本号[双指针截取自己想要的字串]

Getting started with the lockust series
随机推荐
require与import的区别和使用
Four methods of JS array splicing [easy to understand]
Design and practice of new generation cloud native database
【MySQL】数据库优化方法
js数组拼接的四种方法[通俗易懂]
[NOIP2013]积木大赛 [NOIP2018]道路铺设 贪心/差分
MySQL learning notes - SQL optimization of optimization
AIDL基本使用
PWN攻防世界cgpwn2
Introduction and download of the latest version of airserver2022
Introduction à l'ingénierie logicielle (sixième édition) notes d'examen de Zhang haifan
测试撤销1
Getting started with the lockust series
Yan Rong looks at how to formulate a multi cloud strategy in the era of hybrid cloud
Microsoft, Columbia University | Godel: large scale pre training of goal oriented dialogue
Business visualization - make your flowchart'run'up
物联网rfid等
Which securities company should we choose to open an account for flush stock? Is it safe to open an account with a mobile phone?
PCB plug hole technology~
基础—io密集型计算和cpu密集型计算