How to change background color to threshold image

1 view (last 30 days)
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 !

Answers (1)

Ameer Hamza
Ameer Hamza on 28 Mar 2020
Edited: Ameer Hamza on 28 Mar 2020
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);

Products


Release

R2017b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!