フィルターのクリア

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

5 ビュー (過去 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 Center および File ExchangeImage Processing Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by