Changing hair color in a photo using matlab

5 ビュー (過去 30 日間)
yasar ismet Yilmaz
yasar ismet Yilmaz 2021 年 9 月 11 日
コメント済み: DGM 2022 年 11 月 5 日
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 ?

回答 (1 件)

Image Analyst
Image Analyst 2021 年 9 月 11 日
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 件のコメント
yasar ismet Yilmaz
yasar ismet Yilmaz 2021 年 9 月 11 日
I created the image where I changed the hair color and saved it to Workspace. How do I print my saved photo to the screen? (sorry i asked a lot of questions)
Image Analyst
Image Analyst 2021 年 9 月 11 日
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.

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by