MATLAB question: Create a new function called ExtractLayer: ExtractLayer takes t
ID: 2246322 • Letter: M
Question
MATLAB question: Create a new function called ExtractLayer: ExtractLayer takes two arguments: image and layer image: a matrix representing an RGB image in the usual RGB image format (we talked about in class on Friday) layer: a number taking values 1, 2, or 3 representing the red, green, and blue layers respectively (you can assume your function always gets valid input) ExtractLayer returns a matrix representing an image with only the requested color layer (with zeros for the other layers) NOTE: your function should return an RGB image matrix (that's why you need zeros in the other layers--there must always be 3 layers to be a valid RGB matrix). To test the correctness of your code, you can try extracting the layers for this image. For instance, the red layer should be what you get if you call imshow(ExtractLayer(image,1))
Explanation / Answer
This two line function will do your job :)
function results = ExtractLayer(image, layer)
results = zeros(size(image));
results(:, :, layer) = image(:, :, layer);
end
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.