MATLAB Answers

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

2 views (last 30 days)
how to convert from grayscale to rgb by lightness (desaturation) method (matlab code)??
  2 Comments
Hanan Elsayed
Hanan Elsayed on 24 Aug 2021
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);

Sign in to comment.

Accepted Answer

Turlough Hughes
Turlough Hughes on 24 Aug 2021
Edited: Turlough Hughes on 24 Aug 2021
You can do the following:
I=imread('peppers.png');
newImage = uint8(( double(min(I,[],3)) + double(max(I,[],3)) ) ./ 2);
imshow(newImage)
  5 Comments

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!