How to make an image take different RGB values?

조회 수: 1 (최근 30일)
Abdul Rahim Mohammad
Abdul Rahim Mohammad 2019년 4월 10일
댓글: Abdul Rahim Mohammad 2019년 4월 11일
I have an image with NxMx3 uint8 colors but I want the colors of the image to be replaced with another array of 256x3(Each column corresponds to R,G,B values) colors. How can I map the values from the array to the image?
I was advised that I need to split the 3 channels and then map them independently

채택된 답변

Jan
Jan 2019년 4월 10일
편집: Jan 2019년 4월 10일
LUT = randi([0, 255], 256, 3, 'uint8'); % The look up table
Img = randi([0, 255], 640, 480, 3, 'uint8'); % The image
NewImg = cat(3, LUT(Img(:, :, 1) + 1, 1), ...
LUT(Img(:, :, 2) + 1, 2), ... % [EDITED, 3 ==> 2]
LUT(Img(:, :, 3) + 1, 3));
This replaces the original colors by the ones from the look up table by a simple indexing. See this example:
LUT = [2, 4, 8]
Img = [0, 1; 2, 1];
LUT(Img + 1)
  댓글 수: 9
Guillaume
Guillaume 2019년 4월 11일
Jan made a typo. Replace resize by reshape and all will be well.
Abdul Rahim Mohammad
Abdul Rahim Mohammad 2019년 4월 11일
Edit: I got it working, NewImag = reshape(NewImg,size(img)); works to reshape the array into my desired dimensions.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Image Data Workflows에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by