Function that takes 2 input matrices (mxn3 color uint8 and mxn matrix of doubles) and returns an mxnx3 color image.

21 ビュー (過去 30 日間)
I am not asking for the answer to what obviously looks like a hw assignment but rather I am just asking for some direction and clarification. I am not even sure where to start or what exactly I am being asked to do...If someone could just help me understand this prompt or point me towards what topics I should read up on, I would be much obliged.
Write a program that takes an m x n x 3 color image uint8 matrix, and an m x n matrix of doubles as inputs. It should return an m x n x 3 color image.
Your program should:
  1. Convert your matrix of doubles to a matrix of uint8s.
  2. Combine the information from the matrix with the information from EACH COLOR of the image matrix. You should do this by dividing both matrices by 2, and then adding them together in an appropriate way.
  3. Returned the combined matrices as your outputs.
function [] = matrixCombine(colorImage,doubleImage)
doubleImage = doubleImage./2
colorImage(:,:,1)= colorImage(:,:,1)./2 + doubleImage
colorImage(:,:,2)= colorImage(:,:,2)./2 + doubleImage
colorImage(:,:,3)= colorImage(:,:,3)./2 + doubleImage
is all I have so far. Sorry that I obviously have some major gaps in my understanding of programming in MATLAB but I am trying to improve. Thank you for your help.
  2 件のコメント
Walter Roberson
Walter Roberson 2018 年 3 月 19 日
You are missing the step "Convert your matrix of doubles to a matrix of uint8s."
Your function is not returning anything.
rayray
rayray 2018 年 3 月 22 日
Thank you! I totally missed that. I managed to get the code to work! I wasn't sure if I was even on the right track so I appreciate your help

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

回答 (1 件)

Venkata Siva Krishna Madala
Venkata Siva Krishna Madala 2018 年 3 月 22 日
Hello Ray,
I understood your problem and wrote the code as needed.
function outputImage = matrixCombine(colorImage,doubleImage)
t=uint8(doubleImage);
t=t./2;
outputImage(:,:,1)= colorImage(:,:,1)./2 + t;
outputImage(:,:,2)= colorImage(:,:,2)./2 + t;
outputImage(:,:,3)= colorImage(:,:,3)./2 + t;
end
Also, check https://www.mathworks.com/help/matlab/numeric-types.html. It that will help you get a deeper understanding of the Numeric Data Types in MATLAB
Regards,
Krishna Madala

製品

Community Treasure Hunt

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

Start Hunting!

Translated by