当前位置:网站首页>Skills of saving images with different depths in opencv
Skills of saving images with different depths in opencv
2022-04-23 00:01:00 【liiiiiiiiiiiiike】
What is image depth ?
A lot of people start to learn OpenCV after , Several methods of contact include imwrite function , And soon know that you need to pass in a ndarray Type of mat Object as an argument , The general code is as follows :
imwrite("D:/result.png ", dst);#dst by mat object , The previous argument is the saved address
The image saved in this way is each channel by default 8 Bit byte image ( The size of each pixel is 0~255), common RGB The image is an image with a depth of 24, This can be done through windows View the image properties to get , The screenshot is as follows :

If each channel occupies 16 A word of ,RGB The image depth becomes 48, If each channel occupies 32 A word of , The depth becomes 96, Obviously, the deeper the image , There will also be more image files , The more memory will be consumed when loading , therefore OpenCV The default read / write image in is each channel 8 position ( Single byte ) Images .
Preservation of various depth images
After the transformation , If you save directly , The code is as follows :
# Load image
Mat src = imread("D:/flower.png", IMREAD_UNCHANGED);
printf("depth %d \n", src.depth());
# Convert to 16 Bit image
Mat dst;
src.convertTo(dst, CV_16U);
imshow("flower16", dst);
imwrite("D:/flower-16.png", dst);
After the transformation , Normalize and save , The code is as follows :
# Load image
Mat src = imread("D:/flower.png", IMREAD_UNCHANGED);
printf("depth %d \n", src.depth());
# Convert to 16 Bit image
Mat dst;
src.convertTo(dst, CV_16U);
# Normalize and save
normalize(dst, dst, 0, 256 * 256, NORM_MINMAX);
imwrite("D:/flower-16.png", dst);
imshow("flower-16", dst);
The comparison of the two effects is as follows :

# Load image
Mat src = imread("D:/flower.png", IMREAD_UNCHANGED);
printf("depth %d \n", src.depth());
# Convert to 32 Bit image
Mat dst;
src.convertTo(dst, CV_32F);
# Normalize and save
normalize(dst, dst, 0, 1.0, NORM_MINMAX);
imwrite("D:/flower-32.png", dst);
imshow("flower-32", dst);
For the above images with different depths , It must be read correctly in the following way
Mat src = imread("D:/flower.png", IMREAD_UNCHANGED);
版权声明
本文为[liiiiiiiiiiiiike]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204222358593244.html
边栏推荐
- Two color gradients
- SystemVerilog verification - Test Platform preparation guide learning notes (2): process statements and subroutines
- Detailed explanation of MySQL field types
- Q:MATLAB的图像上怎么标记数据点?&Text函数精讲
- Waveform generator based on Multisim
- xpath定位
- Wechat applet page Jump
- FPGA (VI) RTL code II (complex circuit design 1)
- [gestion des transactions]
- 制作目标检测训练样本的方案
猜你喜欢

Thread pool (easy to understand)

FPGA(四)数字IC面试的四个基本问题

Thought of reducing Governance -- detailed summary of binary search

Solve the error reporting problem of require is not defined

The latest MySQL tutorial is easy to understand

Online fox U3D client game configuration loading failed couldn't connect to server

微信小程序页面跳转

BGP基本配置

闭包的实现原理和作用、以及内存泄露

SystemVerilog verification - Test Platform writing guide learning notes (3): connecting design and test platform
随机推荐
Robot OS System Architecture Design
matlab-day01
技术的好文章和烂文章
pycharm界面改为中文,中英文切换
Go language - use CO process to efficiently calculate the accumulation of each number in 0-2000
XPath positioning
Detailed explanation of MySQL index
基于.NetCore开发博客项目 StarBlog - (3) 模型设计
力扣习题集3--无重复字符的最长子串
【leetcode】二叉树,104二叉树的最大深度,543二叉树的直径,124二叉树的最大路径和
3D rotation animation
Data type not supported by ice's mice profiler
【leetcode】二叉树,654最大二叉树,105根据前序与中序遍历构造二叉树,106根据中序与后序遍列构造二叉树,889根据前序和后序遍历构造二叉树
LabVIEW实现应用程序停止或退出
STM32F103 independent watchdog
合并两个有序的数组
[leetcode] binary tree, in-depth understanding of the first, middle and last order
Use example to add a sort invalidation problem when using PageHelper
Thought of reducing Governance -- detailed summary of binary search
L1-075 obsessive compulsive disorder (10 points)