How to change background color to threshold image
1 次查看(过去 30 天)
显示 更早的评论
Hello, i need to change de background color of an image to green, but the image but the image is threshold, I need the values to be 0 change to green color.
clc
clear
close all
imagen = imread('imagenes\AAM.jpg');
imagenOri= imagen; %Imagen Original
imagen = rgb2gray(imagen); %Imagen en escala de grises
%Aplicacion funcion stdfilt
imagenST = stdfilt(imagen);
%Normalizacion
imagenST = imagenST - min (min(imagenST (:)));
imagenST = imagenST / max (imagenST (:));
%Umbralizacion de la imagen
imagenST(imagenST < 0.1) = 0;
imagenST(imagenST > 0.9) = 1;
figure, subplot (1,2,1), imshow(rgbImage), title('Imagen de Entrada ');
subplot (1,2,2), imshow(imagenST), title('Imagen de salida ');

I have the image (a) and the result must be as in image (b)
Thanks !
0 个评论
回答(1 个)
Ameer Hamza
2020-3-28
编辑:Ameer Hamza
2020-3-28
Are you looking for somthing like this
im = im2double(imread('image.png')); % this is the name of your image file
im_gray = rgb2gray(im);
mask = bwareaopen(im_gray < 0.2, 10); % 0.2 threshold was chosen after manually tuning the value
in_mask = 1-mask;
r = in_mask.*im_gray; % make the background value 0 for red channel
g = in_mask.*im_gray + mask; % make the background value 0 for green channel
b = in_mask.*im_gray; % make the background value 0 for blue channel
im_new = cat(3,r,g,b); % create the rgb image
imshow(im_new);
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!