MATLAB: How do i change the skin color in the plotted circle using HSV color space

hsv color spaceImage Processing Toolbox

theta = 0 : 0.01 : 2*pi;
radius = 35;
I = imread('Image1.jpg');
NoseDetect = vision.CascadeObjectDetector('Nose','MergeThreshold',30);
imshow(I);hold on
nbox = step(NoseDetect, I);
nx = nbox(1) + nbox(3)/2;
ny = nbox(2) + nbox(4)/2;
final_x = nx - 120;
final_y = ny - 20;
X = radius * cos(theta) + final_x;
Y = radius * sin(theta) + final_y;
plot(X, Y, 'b-', 'LineWidth', 1);

Best Answer

Try this:
clc; % Clear command window.
clear; % Delete all variables.
close all; % Close all figure windows except those created by imtool.
workspace; % Make sure the workspace panel is showing.
fontSize = 20;
rgbImage = imread('capture.png');
subplot(2, 2, 1);
imshow(rgbImage);
axis on;
title('Original Image', 'FontSize', fontSize);
% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0.05, 1, .95]);
% Get rid of tool bar and pulldown menus that are along top of figure.
% set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
% NoseDetect = vision.CascadeObjectDetector('Nose','MergeThreshold',30);
% Convert to HSV color space.
HSV = rgb2hsv(rgbImage);
subplot(2, 2, 2);
imshow(HSV);
title('HSV Image', 'FontSize', fontSize);
hold on
hueImage = HSV(:,:,1);
satImage = HSV(:,:,2);
valueImage = HSV(:,:,3);
% Create circle perimeter coordinates.
% nbox = step(NoseDetect, I);
% nx = nbox(1) + nbox(3)/2;
% ny = nbox(2) + nbox(4)/2;
% final_x = nx - 120;
% final_y = ny - 20;
final_x = 270;
final_y = 250;
theta = 0 : 0.01 : 2*pi;
radius = 35;
X = radius * cos(theta) + final_x;
Y = radius * sin(theta) + final_y;
plot(X, Y, 'm-', 'LineWidth', 2);
% Create circle mask
[rows, columns] = size(hueImage);
mask = poly2mask(X, Y, rows, columns);
subplot(2, 2, 3);
imshow(mask);
title('Mask Image', 'FontSize', fontSize);
% Change HSV values within the mask only.
hueImage(mask) = 0.5; %hueImage(mask) + 1 / 360 * 400;
satImage(mask) = satImage(mask) + 0.01 * 4;
valueImage(mask) = valueImage(mask) + 0.01 * 3;
% Clip values.
hueImage(hueImage>1)=1; hueImage(hueImage<0)=0;
satImage(satImage>1)=1; satImage(satImage<0)=0;
valueImage(valueImage>1)=1; valueImage(valueImage<0)=0;
% Reconstruct 3-D HSV image.
HSV(:,:,1) = hueImage;
HSV(:,:,2) = satImage;
HSV(:,:,3) = valueImage;
% Convert back to RGB color space for display.
newRGBImage = hsv2rgb(HSV);
subplot(2, 2, 4);
imshow(newRGBImage);
title('Altered Image', 'FontSize', fontSize);