MATLAB: Who know how to do this interpolation problem

beginnerhomeworkinterpolation

Image processing. Write a function to display a color image, as well as its red, green, and blue layers separately. The function declaration should be im=displayRGB(filename). filename should be the name of the image (make the function work for *.jpg images only). imshould be the final image returned as a matrix. To test the function, you should put a jpg file into the same directory as the function and run it with the filename (include the extension, for example im=displayRGB(‘testImage.jpg’)). You can use any picture you like, from your files or off the internet. Useful functions: imread, meshgrid, interp2, uint8, image, axis equal, axis tight.
a.
To make the program work efficiently with all image sizes, first interpolate each color layer of the original image so that the larger dimension ends up with 800 pixels. The smaller dimension should be appropriately scaled so that the length:width ratio stays the same. Use interp2 with cubic interpolation to resample the image.
b.
Create a composite image that is 2 times as tall as the original, and 2 times as wide. Place the original image in the top left, the red layer in the top right, the green layer in the bottom left, and the blue layer in the bottom right parts of this composite image. The function should return the composite image matrix in case you want to save it as a jpg again (before displaying or returning, convert the values to unsigned 8-bit integers using uint8). Hint: To get just a single color layer, all you have to do is set the other two layers to zero. For example if X is an MxNx3 image, then X(:,:,2)=0; X(:,:,3)=0; will retain just the red layer. Include your code and the final image in your homework writeup.
I am a self-taught beginner. And the material I use does not specifically talk about the like "pixels' or how to interpolate each color layer of the original picture, it is focused more on the algebra calculation. Thus, I have no idea at all for this question. Can someone help me? Thanks a lot!

Best Answer

I don't agree with the way your instructor told you to get just a single color layer. Setting other color layers to zero leaves it a color image. Use this code to extract just a single color channel:
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
Aren't there examples for interp2() in the help that you can look at?