How can I reset the colored image after I converted into grayscale?

4 ビュー (過去 30 日間)
Roshni gupta
Roshni gupta 2017 年 8 月 14 日
コメント済み: Image Analyst 2017 年 8 月 14 日
I have 4.jpg as image.1st i am converting it into grayscale to apply imhist(). I am getting grayscale enhanced image as output but I need the enhanced colored image as output. How to do that? I tried using colormap as shown in code below. But its not working
I = imread('4.jpg');
imshow(I)
R = rgb2gray(I);
figure
imshow(R)
in = histeq(R);
figure;
imshow(in);
figure;
imhist(in);
y=colormap(hot(110));
imwrite(R,y,'4.jpg','jpg');
imshow('4.jpg');
% I=imread('4.jpg');
% R=rgb2gray(I); % It is gray now
% % y=colormap(hot(110));
% % imwrite(R,y,'rgb.jpg','jpg'); % Re-change it to colored one
% % T=imread('rgb.jpg');
%
% imshow(T);
% imshow('4.jpg');

採用された回答

Guillaume
Guillaume 2017 年 8 月 14 日
Nothing is stopping you from performing histogram equalisation on each colour channel, if that's what you're after:
rgbimage = imread('4.jpg');
equalisedimage = rgbimage; %copy for simplicity
for channel = 1:3 %iterate over the 3 colour channel
equalisedimage(:, :, channel) = histeq(rgbimage(:, :, channel)); %apply histogram equalisation to each channel
end
imshowpair(rgbimage, equalisedimage, 'montage');
I would advise you to use meaningful variable names as I've done here instead of your meaningless (and misleading!) one letter variable names.
  2 件のコメント
Roshni gupta
Roshni gupta 2017 年 8 月 14 日
Thankyou so much :) its working.
Image Analyst
Image Analyst 2017 年 8 月 14 日
By the way, histogram equalization tends to give crummy looking images and is rarely if ever needed. For example you don't need to do it prior to doing things like thresholding, etc. I've never needed to use it in 40 years of image processing.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeModify Image Colors についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by