How would we use Euclidean Distance Method to assign colours to specific pixels of an image ? For eg. i want to add rainbow in the given image !

3 次查看(过去 30 天)

回答(1 个)

Image Analyst
Image Analyst 2015-2-27
First get an image of a rainbow. Then get a binary mask of where it is in the image. Then separate your two images into color channels.
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
Do the above for each color image. Then do
redChannel(binaryMask) = rainbowRed(binaryMask);
greenChannel(binaryMask) = rainbowGreen(binaryMask);
blueChannel(binaryMask) = rainbowBlue(binaryMask);
rgbout = cat(3, redChannel, greenChannel, blueChannel);
By the way a rainbow in that image would look totally unrealistic. Do you know when you get rainbows? Actually that was my very first homework problem in optics graduate school. We had to find the angle of a rainbow. It's 42 degrees. You need the sun at your back and rain or mist in front of you.

Community Treasure Hunt

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

Start Hunting!

Translated by