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

2 views (last 30 days)
Hanan Elsayed on 24 Aug 2021
Commented: Hanan Elsayed on 24 Aug 2021
how to convert from grayscale to rgb by lightness (desaturation) method (matlab code)?? ##### 2 CommentsShowHide 1 older comment
Hanan Elsayed on 24 Aug 2021
This is my last attempt, but it didn't work
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 on 24 Aug 2021
Edited: Turlough Hughes on 24 Aug 2021
You can do the following:
newImage = uint8(( double(min(I,[],3)) + double(max(I,[],3)) ) ./ 2);
imshow(newImage) Hanan Elsayed on 24 Aug 2021
Thank you, I benefited a lot 💜💜💜💜

### Categories

Find more on Convert Image Type in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!