【发布时间】:2015-06-30 06:14:22
【问题描述】:
我知道thread 关于同时将黑色转换为白色和将白色转换为黑色。 我只想将黑色转换为白色。 我知道 thread 会按照我的要求执行此操作,但我不明白出了什么问题。
图片
代码
rgbImage = imread('ecg.png');
grayImage = rgb2gray(rgbImage); % for non-indexed images
level = graythresh(grayImage); % threshold for converting image to binary,
binaryImage = im2bw(grayImage, level);
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
% Make the black parts pure red.
redChannel(~binaryImage) = 255;
greenChannel(~binaryImage) = 0;
blueChannel(~binaryImage) = 0;
% Now recombine to form the output image.
rgbImageOut = cat(3, redChannel, greenChannel, blueChannel);
imshow(rgbImageOut);
这给了
红色通道似乎有问题。 黑色只是 RGB 中的 (0,0,0),因此删除它意味着将每个 (0,0,0) 像素变为白色 (255,255,255)。 与
一起做这个想法redChannel(~binaryImage) = 255;
greenChannel(~binaryImage) = 255;
blueChannel(~binaryImage) = 255;
给予
所以我一定误解了 Matlab 中的某些内容。蓝色不应有任何黑色。所以最后这张图很奇怪。
你怎么能只把黑色变成白色? 我想保持心电图的蓝色。
【问题讨论】:
标签: image matlab image-processing colors rgb