当前位置:网站首页>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)
边栏推荐
- 按照功能对Boost库进行分类
- 业务可视化-让你的流程图'Run'起来
- 旁路由设置的正确方式
- 一次调试去了解redis集群的slot机制
- 杰理之关于长按开机检测抬起问题【篇】
- Manually implement function isinstanceof (child, parent)
- Separate the letters and numbers in the string so that the letters come first and the array comes last
- Internet of things RFID, etc
- 打出三位数的所有水仙花数「建议收藏」
- 【MySQL】explain的基本使用以及各列的作用
猜你喜欢
随机推荐
ICML2022 | 基于元语义正则化的介入性对比学习
Electron学习(三)之简单交互操作
杰理之烧录上层版物料需要【篇】
[STM32] stm32cubemx tutorial II - basic use (new projects light up LED lights)
指标陷阱:IT领导者易犯的七个KPI错误
locust 系列入门
vscode的使用
Do you want to make up for the suspended examination in the first half of the year? Including ten examinations for supervision engineers, architects, etc
A debugging to understand the slot mechanism of redis cluster
测试撤销1
JS how to get a list of elements in a collection object
Flume面试题
ngnix基础知识
Internet of things RFID, etc
MySQL learning notes - SQL optimization of optimization
require与import的区别和使用
LIS (longest ascending subsequence) problem that can be understood [easy to understand]
Go - exe corresponding to related dependency
收到一封CTO来信,邀约面试机器学习工程师
Difference and use between require and import








