0
Follow
0
View

Ask matlab rgb to hsv related!

dadawfj 注册会员
2023-02-26 17:11

Part of the answer references GPT, GPT_Pro better solution
This code is used to filter pixels in RGB images that do not fall within a specific hue range, That is, parameters in the HSV(hue, saturation, brightness) space are used for color filtering. Where hsv is a Boolean array that marks whether a pixel is filtered, i.e. whether the pixels in the filtered image are valid.

First line of code "filter_hsv =-(original hsv(:,:,1))> 8.16 "marks pixels whose Hue value exceeds 8.16 in the HSV space as False, which means that the pixel will be filtered.

the second line of code "filter_hsv - = filter_hsv. *(original_hsv(:, :, 2)) & gt; The Saturation value of an HSV space is marked as False, indicating that the pixel whose value exceeds 8.53 is filtered.

The third line of code "filter_hsv -= filter_hsv.*(original hsv(:,:,2)" marks the pixel whose Value exceeds 9.95 in the HSV space as False, meaning that the pixel will be filtered.

In a word, this code is to filter the color of RGB images through HSV, so as to get a certain color picture.

//代码实例
//RGB图片颜色过滤
// 读取图片
original_rgb = imread('path/to/image'); 
// RGB转HSV
original_hsv = rgb2hsv(original_rgb); 
// 初始化一个Boolean数组,用来标记某一像素是否被过滤 
filter_hsv = true(size(original_rgb)); 
// HSV参数如下 
hue = 8.16; 
saturation = 8.53; 
value = 9.95; 
// 过滤Hue 
filter_hsv = filter_hsv & (original_hsv(:,:,1) > hue); 
// 过滤Saturation 
filter_hsv = filter_hsv & (original_hsv(:,:,2) > saturation); 
// 过滤Value 
filter_hsv = filter_hsv & (original_hsv(:,:,3) > value); 
// 将所有标记为false的像素全部重新映射为黑色 
filtered_rgb = original_rgb; 
filtered_rgb(repmat(~filter_hsv, [1, 1, 3])) = 0; 
// 显示图片 
imshow(filtered_rgb);  

If the answer is helpful, please accept it.

ddk35785 注册会员
2023-02-26 17:11

The following answers are quoted from GPT-3 model, please use them wisely:

的matlab实现!

上述代码的意思是:从原来的RGB图像中计算出HSV值后,提取HSV值中符合特定要求的像素,并将其保存在一个二维数组中(hsv)。比如,在这段代码中,要求Hue(original_hsv(:,:,1))大于0.16,Saturation(original_hsv(:,:,2))在0.5~0.6之间,Value(original_hsv(:,:,3))大于0.95,对应的Matlab代码实现如下:

% 读入原始RGB图像
I = imread('example.jpg');

% RGB转HSV
I_hsv = rgb2hsv(I);

% 计算满足Hue>0.16,Saturation<0.6&>0.5,Value>0.95的像素位置
H = I_hsv(:,:,1);
S = I_hsv(:,:,2);
V = I_hsv(:,:,3);

filtered_H = H > 0.16;
filtered_S = S > 0.5 & S < 0.6;
filtered_V = V > 0.95;

Filter = filtered_H .* filtered_S .* filtered_V;

Please accept my answer if it answers your question

About the Author

Question Info

Publish Time
2023-02-26 17:11
Update Time
2023-02-26 17:11

Related Question

Automapper:更新集合

使用相同的查询,从数据库中获取Administrator角色的所有数据,而不是其他角色的所有数据

使用CustomAdapter进行搜索

颤振FirebaseFirestore

jtessboxeditor训练字库遇到的问题

有人成功地在coremltools网站上运行了快速入门示例吗?

Matlab 三维数组以二维数组元素为准做平均

matlab中sphere、eigs等函数用不了,如何解决?

求MATLAB函数ScalarLayerDisplay的代码

RangeError [ERR_FS_FILE_TOO_LARGE]: File size(9509257216)大于2gb