RGB图像-像素、分辨率、相关概念

本文深入探讨RGB图像,包括RGB的基本理解,如RGB16、RGB24、RGB32的分类,以及图像的分辨率、图像深度、像素深度和位深等关键概念,帮助理解颜色表示和图像存储原理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一:RGB

1> RGB 基本理解

RGB指的是R(red)红色、G(green)绿色、B(blue)蓝色,三种颜色;目前来说,所有的颜色都可以用这三种颜色配出来,RGB各有256级亮度,用数字表示为从0、1、2…直到255,最多为56×256×256=16777216;简称为1600万色或千万色。也称为24位色(2的24次方)

在这里插入图片描述

2> RGB分类RGB16\RGB24\RGB32

RGB-num: num 数字就是num位(num/8个字节)为一个存储单元,来存储一个RGB像素,RGB16\RGB24\RGB32三者的排列顺序不同;

1. RGB16

RGB:16 位为一个存储单元,来存储一个RGB像素;因为人眼对绿色比较敏感,所以有时候会用6位绿色,有时候会用5位,分为 RGB565、RGB555

RGB565
RGB565就是R占比5位,G占比6位,B占比5位

高字节                               低字节
R R R R R G G G G G G B B B B B
<
在C语言中,RGB图像像素通常是以数组的形式存储,每个像素由红(R)、绿(G)、蓝(B)三个分量组成。如果你想要实现1200分辨率图像的缩放,可以按照以下步骤操作: 1. 定义图像数据结构: ```c typedef struct { unsigned char red; unsigned char green; unsigned char blue; } Pixel; ``` 2. 定义二维像素数组,假设原图宽度为`original_width`,高度为`original_height`: ```c Pixel original_image[original_height][original_width]; ``` 3. 缩放函数,这里以线性插值为例,假设目标分辨率是`target_width`和`target_height`: ```c void resize_image(Pixel target_image[target_height][target_width], const Pixel* source_image, int source_width, int source_height, int scale_factor) { for (int y = 0; y < target_height; ++y) { for (int x = 0; x < target_width; ++x) { int source_x = x * scale_factor; int source_y = y * scale_factor; // 确保边界处理 if (source_x >= 0 && source_x < source_width && source_y >= 0 && source_y < source_height) { int r1 = source_image[source_y][source_x].red; int g1 = source_image[source_y][source_x].green; int b1 = source_image[source_y][source_x].blue; int r2 = source_y + 1 < source_height ? source_image[source_y + 1][source_x].red : r1; int g2 = source_y + 1 < source_height ? source_image[source_y + 1][source_x].green : g1; int b2 = source_y + 1 < source_height ? source_image[source_y + 1][source_x].blue : b1; int rx = ((x + 1) / target_width) * scale_factor; int gy = ((y + 1) / target_height) * scale_factor; target_image[y][x] = { (r1*(1-gy) + r2*gy), (g1*(1-gy) + g2*gy), (b1*(1-gy) + b2*gy) }; } else { // 边界像素直接复制 target_image[y][x] = source_image[source_y/source_height][source_x/source_width]; } } } } ``` 4. 调用上述函数并传入原始像素数组、目标尺寸等信息: ```c resize_image(target_image, original_image, original_width, original_height, 1200.0 / target_width); ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

45度看我

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值