How to change all the colours in the image to black
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Elysi Cochin
el 26 de En. de 2021
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/499873/image.jpeg)
how to change all the colours in the image to black except the white colour in image?
0 comentarios
Respuesta aceptada
Timo Dietz
el 26 de En. de 2021
Editada: DGM
el 9 de Mzo. de 2023
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 comentarios
Más respuestas (1)
yanqi liu
el 1 de Feb. de 2021
clc; clear all; close all;
I = imread('ceshi.png');
I2 = rgb2hsv(I);
s = mat2gray(I2(:,:,2));
bw = im2bw(s, 0.5);
figure; imshow(~bw)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/505998/image.png)
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!