I am trying to change the pupil of the following image:
This is not a featur
Here is a solution for manual selection of the pupil. Basically you select a color with which to want to fill the pupil, then trace a region of interest by hand and the region gets filled. In the example I selected a ridiculously large region but you see the point :)
Here is the code:
clear
clc
close all
A = imread('pupil.jpg');
imshow(A)
%// Create dialog box to choose color to fill.
ListColors = {'red' 'green' 'blue' 'magenta' 'white' 'yellow' 'cyan' 'random'};
[Selection,ok] = listdlg('ListString',ListColors,'PromptString','Choose color','SelectionMode','single');
%//Freehand tool
hHand = imfreehand(gca,'Closed',true);
%// createMask is a method from imfreehand. Image processing toolbox required.
mask = createMask(hHand);
%// Create color mask. You can create your own mask with any 3-element vector.
switch ListColors{Selection}
case 'red'
colormask = 255*[1, 0, 0];
case 'green'
colormask = 255*[0, 1, 0];
case 'blue'
colormask = 255*[0, 0, 1];
case 'white'
colormask = 255*[1, 1, 1];
case 'yellow'
colormask = 255*[1, 1, 0];
case 'magenta'
colormask = 255*[1, 0, 1];
case 'cyan'
colormask = 255*[0, 1, 1];
case 'random'
colormask = 255*[rand(1), rand(1), rand(1)];
end
% Extract the individual channels.
redChannel = A(:, :, 1);
greenChannel = A(:, :, 2);
blueChannel = A(:, :, 3);
%// Apply mask to the ROI
redChannel(mask) = colormask(1);
greenChannel(mask) = colormask(2);
blueChannel(mask) = colormask(3);
%// Generate 3 channels final image
A = cat(3, redChannel, greenChannel, blueChannel);
imshow(A)
A few screenshots to show you the output:
1) Select the color (here random)
2) Trace the region
3) Output:
That was fun haha hope that helps!