How to change all the colours in the image to black
조회 수: 3 (최근 30일)
이전 댓글 표시
how to change all the colours in the image to black except the white colour in image?
댓글 수: 0
채택된 답변
Timo Dietz
2021년 1월 26일
편집: DGM
2023년 3월 9일
Try this:
imageData = imread([yourFile]);
% split R, G, B
imgR = imageData(:, :, 1);
imgG = imageData(:, :, 2);
imgB = imageData(:, :, 3);
% get linear index of all pixels with color not white
colIdx = (imgR < 1 | imgG < 1 | imgB < 1);
% change color to black
imgR(colIdx) = 0;
imgG(colIdx) = 0;
imgB(colIdx) = 0;
% write back to new image data or overwrite the origin imageData
newImage(:, :, 1) = imgR;
newImage(:, :, 2) = imgG;
newImage(:, :, 3) = imgB;
댓글 수: 0
추가 답변 (1개)
yanqi liu
2021년 2월 1일
clc; clear all; close all;
I = imread('ceshi.png');
I2 = rgb2hsv(I);
s = mat2gray(I2(:,:,2));
bw = im2bw(s, 0.5);
figure; imshow(~bw)
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!