replace RGB values with new values

1 次查看(过去 30 天)
How to change the pixel values of a RGB image to
% if pixel value is in the following range
0-64 to 0
65-128 to 1
129-192 to 2
192-255 to 3
How to change in all the channels without using for loop

采纳的回答

Dyuman Joshi
Dyuman Joshi 2022-5-25
编辑:Dyuman Joshi 2022-5-25
rgb=[67,68,69;0,67,69;0,66,68;125,126,127;122,125,127;117,122,126;113,114,115;110,113,115;106,111,114]
rgb = 9×3
67 68 69 0 67 69 0 66 68 125 126 127 122 125 127 117 122 126 113 114 115 110 113 115 106 111 114
floor(abs(rgb-1)/64)
ans = 9×3
1 1 1 0 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
  2 个评论
DGM
DGM 2022-5-25
If the input is properly uint8 class, then the output won't be as expected. So long as the input is at least scaled [0 255], the following should work regardless of input class, and the output will be cast properly for the scale.
uint8(floor(abs(double(rgb)-1)/64))
Elysi Cochin
Elysi Cochin 2022-5-25
编辑:Elysi Cochin 2022-5-25
Thank you both of you. For uint8 @DGM comment should be considered.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Images 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by