【发布时间】:2017-07-30 22:40:25
【问题描述】:
如何从图像中删除所有黑色像素并仅使用图像中的唯一 RGB 值
What I'm trying to do is:
1) delete all black pixels from the image and only use the unique RGB colors found in the image
2) export each combined RGB color pixels that is unique as a separate 640x480 image
3) Convert / join these images into a movie file.
我的想法是在哪里将我的红色、绿色和蓝色通道拆分为相应的颜色,并将它们重新整形为三个数组,每个数组一列。 并开始删除黑色像素。
如何删除所有黑色的单元格值(其中 R、G、B 通道为 0)并且只查找/使用唯一的 RGB 值
我附上了下面的图片和代码的sn-p:
resize_tmp_red=reshape(fintersect_red',[1,1200*1200])(:); %will cause array to be created / reshaped left to right and top to bottom (like reading a book) into 1 column
resize_tmp_green=reshape(fintersect_green',[1,1200*1200])(:);
resize_tmp_blue=reshape(fintersect_blue',[1,1200*1200])(:);
%How can I delete all cell values that are black (where the R,G,B channels are 0) and only find / use the RGB values that are unique in the image
for cc=1:10
repmat_rgb(:,:,1)=uint8(repmat(resize_tmp_red(cc,1),[640,480])); %creates 640x480 image of RGB taken from deleted black and unique color array.
repmat_rgb(:,:,2)=uint8(repmat(resize_tmp_green(cc,1),[640,480]));
repmat_rgb(:,:,3)=uint8(repmat(resize_tmp_blue(cc,1),[640,480]));
%imshow(repmat_rgb)
imwrite(repmat_rgb,strcat('/tmp/',sprintf('%03d', cc),'_img.png')); %creates image file
end
PS:我使用的是 Octave 4.0,它类似于 Matlab。 是的,我将不再看到原始图像的结构。我将根据图像中的独特颜色创建一部电影。
【问题讨论】:
-
您想用其他颜色替换黑色像素吗?还是您只是想要所有非黑色颜色的“图像”?请注意,在第二个选项中,您将不再看到原始图像的结构。
-
@Cecilia 我只想要非黑色且独特的颜色。正确我将不再看到原始图像的结构。我将根据图像中的独特颜色创建一部电影。
-
那么预期的输出是什么?您是否想要一个二维颜色矩阵,其中每一行都是唯一的非黑色 RGB 颜色?
-
@rayryeng 是的:-)
-
你想去掉每个通道中的零还是只去掉 (0,0,0)?
标签: arrays image matlab colors octave