Changing hair color in a photo using matlab
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
rgbColorImage = imread('peppers.png');
% Extract the individual red, green, and blue color channels.
redChannel = rgbColorImage{ii}(:, :, 1);
greenChannel = rgbColorImage{ii}(:, :, 2);
blueChannel = rgbColorImage{ii}(:, :, 3);
% Specify the color we want to make this area.
desiredColor = [146, 40, 146]; % Purple
% Make the red channel that color
redChannel(maskedImage) = desiredColor(1);
greenChannel(maskedImage) = desiredColor(2);
blueChannel(maskedImage) = desiredColor(3);
% Recombine separate color channels into a single, true color RGB image.
rgbColorImage{ii} = cat(3, redChannel, greenChannel, blueChannel);
Undefined function or variable 'ii'.
Error in color_change_red_into_blue (line 92)
redChannel = rgbColorImage{ii}(:, :, 1);
I get this error. What do you recommend ?
Réponses (1)
Image Analyst
le 11 Sep 2021
rgbImage is not a cell array so you don't use braces. Get rid of the {ii}. It should be done like
% Extract the individual red, green, and blue color channels.
[redChannel , greenChannel, blueChannel] = imsplit(rgbColorImage);
maskedImage has not been defined at all, so that will cause an error when your program gets to that. You need to define maskedImage as a binary image in order to use it as a logical image like you're trying.
4 commentaires
Image Analyst
le 11 Sep 2021
OK, good. Glad you got it working. To display (not print) the image to the screen you can use imshow():
imshow(rgbImage);
assuming the variable you saved to the workspace is called rgbImage.
Voir également
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!