我有一个RGB图像帧,我想删除所有不是所需颜色的像素。
如果没有for循环怎么办呢?
% Desired color: R 105, G 112, B 175
% I want to zero all pixels that are not this color (plus a tad).
red_target = 105;
green_target = 112;
blue_target = 175;
tad = 4;
red_low = red_target - tad;
red_hi = red_target + tad;
green_low = green_target - tad;
green_hi = green_target + tad;
blue_low = blue_target - tad;
blue_hi = blue_target + tad;
% Filter out non-target colors:
% Pixel redness is within target; greenness is within target; and blueness within:
% Reset pixel if wrong redness OR wrong greenness OR wrong blueness:
raw_frame_size = size( raw_frame )
rows = raw_frame_size( 1 );
columns = raw_frame_size( 2 );
for row = 1:rows
for column = 1:columns
% Reset RGB pixel value if pixel is outside desired range:
pixel_redness = raw_frame(row,column,1);
pixel_greenness = raw_frame(row,column,2);
pixel_blueness = raw_frame(row,column,3);
if ( ( pixel_redness < red_low ) | ( pixel_redness > red_hi ) ...
| ( pixel_greenness < green_low ) | ( pixel_greenness > green_hi ) ...
| ( pixel_blueness < blue_low ) | ( pixel_blueness > blue_hi ) )
raw_frame( row, column, 1 ) = 0;
raw_frame( row, column, 2 ) = 0;
raw_frame( row, column, 3 ) = 0;
end
end
end