Question

We are supposed to make the matlab code below work to recolor the image to maize...

We are supposed to make the matlab code below work to recolor the image to maize and blue

lab3_1recolor.m:

function [ outputImg ] = lab31recolor(hsvImg)

% This function takes an hsv image.

% An image is composed of 3 matrices (hue, saturation, and value).

% This function fixes the colors of the OSU algorithm.

% The corrected image is assigned into outputImg.

% Obtains the hue and saturation layers from the matrix

% An image has 3D dimensions, which is why we use hsvImg(:, :, layer)

hue = hsvImg(:, :, 1);

sat = hsvImg(:, :, 2);

  

% Fix the green and make it blue

hue(0.35 > hue & hue > 0.25) = hue .* 2;

% Replace the red with yellow

hue(.15 > hue | (1 > hue & hue > .97)) = 0.15;

% Increase saturation by a multiplier of 1.2 to make colors more vivid

sat(:, :) .* 1.2 = sat(:, :);

  

% We modified hue and sat

% We need to copy these back into hsvImg!

hsvImg(:, :, 1) = hue;

hsvImg(:, :, 2) = sat;

end

lab3_1_test.m:

% Read the image from the file

img = imread('evil2.jpg'); % hardcode as evil1.jpg or evil2.jpg

% Converts from RGB to HSV (hue, value, saturation)

img = rgb2hsv(img);

% Fixes the image with our function

img = lab1_3_recolor(img);

% Converts from HSV to RGB

img = hsv2rgb(img);

% Displays the image

imshow(img);

0 0
Add a comment Improve this question Transcribed image text
Answer #1

% lab31recolor.m : Matlab function to recolor the image

function [ outputImg ] = lab31recolor(hsvImg)

% This function takes an hsv image.
% An image is composed of 3 matrices (hue, saturation, and value).
% This function fixes the colors of the OSU algorithm.
% The corrected image is assigned into outputImg.
% Obtains the hue and saturation layers from the matrix
% An image has 3D dimensions, which is why we use hsvImg(:, :, layer)
  
outputImg = hsvImg; % copy the values of hsvImg to outputImg
% obtain the hue values
hue = hsvImg(:, :, 1);
% obtain the saturation values
sat = hsvImg(:, :, 2);


% Fix the green and make it blue
hue(0.35 > hue & hue > 0.25) = hue(0.35 > hue & hue > 0.25) .* 2;

% Replace the red with yellow
hue(.15 > hue | (1 > hue & hue > .97)) = 0.15;

% Increase saturation by a multiplier of 1.2 to make colors more vivid
sat(:, :) = sat(:, :).* 1.2;

% We modified hue and sat
% We need to copy these back into hsvImg!

outputImg(:, :, 1) = hue;
outputImg(:, :, 2) = sat;

end

%end of function

%main script

% Read the image from the file

img = imread('evil2.jpg.png'); % hardcode as evil1.jpg or evil2.jpg

% Converts from RGB to HSV (hue, value, saturation)

img = rgb2hsv(img);

% Fixes the image with our function

img = lab31recolor(img);

% Converts from HSV to RGB

img = hsv2rgb(img);

% Displays the image

imshow(img);

%end of script

Output:

Input image:

phpwTdY1d.png

Output Image:

0 x Figure 1 Eile Edit View Insert Tools Desktop Window Help &03 AG OEDO M

Add a comment
Know the answer?
Add Answer to:
We are supposed to make the matlab code below work to recolor the image to maize...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • the picture above is the one you are supposed to use for the MATlab code please...

    the picture above is the one you are supposed to use for the MATlab code please help Problems. Grayscale images are composed of a 2D matrix of light intensities from O (Black) to 255 (White). In this lab you will be using grayscale images and do 2D-array operations along with loops and iflelse branches. 1. We can regard 2D grayscale images as 2D arrays. Now load the provided image of scientists at the Solvay Conference in 1927 using the imread)...

  • use MATLAB to upload the following: an image that you want to process (can be taken...

    use MATLAB to upload the following: an image that you want to process (can be taken yourself or downloaded from the internet) a script that processes the image in TWO ways. manipulates the colors averages pixels together Please make sure the script displays the images (like how I did with the 40 and 80 pixel averaging) so I can easily compare them to the original. Make sure to COMMENT your code as well. Homework 13 Please upload the following: an...

  • from PIL import Image import random # NOTE: Feel free to add in any constant values...

    from PIL import Image import random # NOTE: Feel free to add in any constant values you find useful to use BLACK = (0, 0, 0) WHITE = (255, 255, 255) # NOTE: Feel free to add in any helper functions to organize your code but # do NOT rename any existing functions (or else, autograder # won't be able to find them!!) # NOTE: The following function is already completed for you as an example # You can use...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT