当前位置:网站首页>MATLAB在做图像处理时容易出现的一个误区:为提高运算速度使用预先声明的零矩阵存储图像数据
MATLAB在做图像处理时容易出现的一个误区:为提高运算速度使用预先声明的零矩阵存储图像数据
2022-06-21 20:40:00 【吉大秦少游】
MATLAB在做图像处理时容易出现的一个误区:为提高运算速度使用预先声明的零矩阵存储图像数据。
这个误区很隐蔽,因为这样预先声明的零矩阵可以显著提高运算速度,所以往往会认为是正确的做法。但是为了保证图像数据看起来正常,往往又需要使用im2double函数将输入的图像数据转化为double类型的矩阵,这样imshow出来的图像看起来正常,实际上图像数据由于格式转换导致精度已经有所变化,做数据处理时往往容易报错。
如下:注释部分的代码容易导致图像数据变化。
src_img = strcat(img_path, img_name);
pure_name = size(img_name,2);
pic_odd_name = strcat(img_name(1:pure_name-4), '_odd.bmp');
pic_even_name = strcat(img_name(1:pure_name-4), '_even.bmp');
pic = imread(src_img);
% pic = im2double(pic);
[pic_height, pic_width, rgb_depth] = size(pic);
% pic_odd = zeros([pic_height, pic_width/2, rgb_depth]);
% pic_even = zeros([pic_height, pic_width/2, rgb_depth]);
for i = 1:1:pic_height
for j = 1:1:pic_width
% for k = 1:1:rgb_depth
if(mod(j,2) == 1) % even pixel
pic_even(i,(j+1)/2,:) = pic(i,j,:);
else
pic_odd(i,j/2,:) = pic(i,j,:);
end
% end
end
end
因此,可以直接做处理即可,不用提前声明存储空间的大小,慢是慢一点。还一个做法是在图像数据读到工作区后观察图像数据的类型,再声明同样类型的零矩阵,这个做法理论上也可行,相比于不声明存储空间,在处理大量图像时速度可以快不少。
边栏推荐
- [in depth understanding of tcapulusdb technology] tcapulusdb business data backup
- 更好的管理各种音乐,专业的DJ音乐管理软件Pioneer DJ rekordbox
- cpu指令重排导致错误的一个例子
- GDB debugging practice (8) transfer startup parameters to the program
- Use the do while loop to calculate the odd and even sums in 1-100 [method 1]
- 班主任让开股票账户,在启牛开户安全吗?
- 项目流程管理工具OmniPlan Pro 4
- Use the do while loop to calculate the odd and even sums in 1-100 [method 2]
- RTX3090 与pytorch版本对应关系
- 软件架构介绍
猜你喜欢

Leetcode question brushing: SF Technology Smart logistics Campus Technology Challenge

flutter系列之:flutter中的IndexedStack

力扣刷題集結4(mysql版本)

About Eureka starting successfully but accessing 404
![[in depth understanding of tcapulusdb technology] tcapulusdb construction data](/img/64/4d7ec393d8469cdadc89078a8cf4b1.png)
[in depth understanding of tcapulusdb technology] tcapulusdb construction data

HIC Pro | HIC data processing tool

IP guard printing control to prevent information disclosure of printing channels

LeetCode-543-二叉树的直径

HiC-Pro | HiC数据处理工具
![[deeply understand tcapulusdb technology] tmonitor module architecture](/img/7b/8c4f1549054ee8c0184495d9e8e378.png)
[deeply understand tcapulusdb technology] tmonitor module architecture
随机推荐
【深入理解TcaplusDB技术】TcaplusDB导入数据
可乐与凉茶加速互卷
Font size in DataGridView of C #
leetcode刷题:顺丰科技智慧物流校园技术挑战赛
如何卸载用conda命令安装的包
[deeply understand tcapulusdb technology] one click installation of tmonitor background
GDB debugging skills (0) getting started with GDB
Qt滚动区域QScrollArea
Anaconda add channels
Use the while loop to calculate the odd and even sums in 1-100 [method 2]
A callback was made to a garbage collected delegate of type "xxx:: invoke". This can cause application crashes, corruption, and data loss. When passing delegates to unmanaged code, the managed applica
利用for循环,分别计算1-100中奇数的和、偶数的和【方法二】
Technology sharing | mysql:caching_ sha2_ Password quick Q & A
Li Kou: Change
小程序与工业互联网能够相辅相成的原因
File i/o
弗吉尼亚大学:Ingy ElSayed-Aly | 多智能体强化学习中的基于逻辑的奖励形成
IQtree|构建进化树的软件
Chess and card games
班主任让开股票账户,在启牛开户安全吗?