当前位置:网站首页>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)
边栏推荐
- Flume面试题
- Burpsuite simple packet capturing tutorial [easy to understand]
- 首席信息官对高绩效IT团队定义的探讨和分析
- 最近公共祖先离线做法(tarjan)
- 【MySQL】数据库优化方法
- LIS (longest ascending subsequence) problem that can be understood [easy to understand]
- ICML2022 | 基于元语义正则化的介入性对比学习
- 上半年暂停考试要补考?包含监理工程师、建筑师等十项考试
- [NOIP2013]积木大赛 [NOIP2018]道路铺设 贪心/差分
- [STM32] stm32cubemx tutorial II - basic use (new projects light up LED lights)
猜你喜欢
随机推荐
九章云极DataCanvas公司蝉联中国机器学习平台市场TOP 3
PCB plug hole technology~
【智能QbD风险评估工具】上海道宁为您带来LeanQbD介绍、试用、教程
业务可视化-让你的流程图'Run'起来
The correct way to set the bypass route
String type conversion BigDecimal, date type
Burpsuite simple packet capturing tutorial [easy to understand]
String类型转换BigDecimal、Date类型
C中main函数的几种写法
编程英语生词笔记本
Using closures to switch toggle by clicking a button
首席信息官对高绩效IT团队定义的探讨和分析
基于K-means的用户画像聚类模型
分离字符串中的字母和数字并使得字母在前数组在后
News classification based on LSTM model
同花顺股票开户选哪个券商好手机开户是安全么?
Qtreeview+qabstractitemmodel custom model: the third of a series of tutorials [easy to understand]
杰理之、产线装配环节【篇】
Introduction à l'ingénierie logicielle (sixième édition) notes d'examen de Zhang haifan
The difference between NiO and traditional IO









