how to convert from grayscale to rgb by lightness method ??

조회 수: 3 (최근 30일)
Hanan Elsayed
Hanan Elsayed 2021년 8월 24일
댓글: Hanan Elsayed 2021년 8월 24일
how to convert from grayscale to rgb by lightness (desaturation) method (matlab code)??
  댓글 수: 2
Turlough Hughes
Turlough Hughes 2021년 8월 24일
What have you tried so far?
Hanan Elsayed
Hanan Elsayed 2021년 8월 24일
This is my last attempt, but it didn't work
i=imread('peppers.png');
for j=1:size(i,1)
for k=1:size(i,2)
if i(j,k,1)>i(j,k,2)&&i(j,k,3)
max=i(j,k,1);
elseif i(j,k,2)>i(j,k,1)&&i(j,k,3)
max=i(j,k,2);
else
max=i(j,k,3);
end
if i(j,k,1)<i(j,k,2)&&i(j,k,3)
min=i(j,k,1);
elseif i(j,k,2)<i(j,k,1)&&i(j,k,3)
min=i(j,k,2);
else
min=i(j,k,3);
end
newimage=(max+min)/2;
end
end
imshow(newimage);

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

채택된 답변

Turlough Hughes
Turlough Hughes 2021년 8월 24일
편집: Turlough Hughes 2021년 8월 24일
You can do the following:
I=imread('peppers.png');
newImage = uint8(( double(min(I,[],3)) + double(max(I,[],3)) ) ./ 2);
imshow(newImage)
  댓글 수: 5
Turlough Hughes
Turlough Hughes 2021년 8월 24일
Thanks @Image Analyst. I should have converted to a datatype not capped at 255 in order to add the values. I've edited the answer with the correction.
Actually, one could also just do the following without converting datatypes:
I=imread('peppers.png');
newImage = min(I,[],3)./2 + max(I,[],3)./2;
imshow(newImage)
Hanan Elsayed
Hanan Elsayed 2021년 8월 24일
Thank you, I benefited a lot 💜💜💜💜

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Convert Image Type에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by