当前位置:网站首页>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)
边栏推荐
- js数组拼接的四种方法[通俗易懂]
- String type conversion BigDecimal, date type
- [commercial terminal simulation solution] Shanghai daoning brings you Georgia introduction, trial and tutorial
- 微软、哥伦比亚大学|GODEL:目标导向对话的大规模预训练
- js如何获取集合对象中某元素列表
- 辅音和声母的区别?(声母与辅音的区别)
- 旁路由设置的正确方式
- require与import的区别和使用
- 【STM32】STM32CubeMX教程二–基本使用(新建工程点亮LED灯)
- 面试题:MySQL的union all和union有什么区别、MySQL有哪几种join方式(阿里面试题)[通俗易懂]
猜你喜欢
基于LSTM模型实现新闻分类
Flume面试题
【MySQL】explain的基本使用以及各列的作用
[noip2013] building block competition [noip2018] road laying greed / difference
【直播回顾】战码先锋首期8节直播完美落幕,下期敬请期待!
东哥套现,大佬隐退?
Design and practice of new generation cloud native database
Manually implement function isinstanceof (child, parent)
Little p weekly Vol.11
企业架构与项目管理的关联和区别
随机推荐
业务可视化-让你的流程图'Run'起来
[noip2013] building block competition [noip2018] road laying greed / difference
[NOIP2013]积木大赛 [NOIP2018]道路铺设 贪心/差分
Several ways of writing main function in C
同花顺股票开户选哪个券商好手机开户是安全么?
One of the basic learning of function
String type conversion BigDecimal, date type
物联网rfid等
PWN攻防世界cgpwn2
浏览器tab页之间的通信
【单体】流辰信息I-BPSv3服务器推荐配置
面试题:MySQL的union all和union有什么区别、MySQL有哪几种join方式(阿里面试题)[通俗易懂]
工控设备安全加密的意义和措施
Make a three digit number of all daffodils "recommended collection"
灵动微 MM32 多路ADC-DMA配置
CNN convolution neural network principle explanation + image recognition application (with source code) [easy to understand]
Pytest collection (2) - pytest operation mode
测试撤销1
[live broadcast review] the first 8 live broadcasts of battle code Pioneer have come to a perfect end. Please look forward to the next one!
PCB线路板塞孔工艺的那些事儿~