How to show histogram of RGB image in Matlab?

后端 未结 5 1126
离开以前
离开以前 2020-12-05 18:46

I read an image in matlab using

input = imread (\'sample.jpeg\');

Then I do

imhist(input);

It gives this

相关标签:
5条回答
  • 2020-12-05 19:23
    img1=imread('image.jpg');
    img1=rgb2gray(img1);
    subplot(2,2,1);
    imshow(img1);
    title('original image');
    grayImg=mat2gray(img1);
    subplot(2,2,2);
    imhist(grayImg);
    title('original histogram');
    

    Remember to include mat2gray(); because it converts the matrix A to the intensity image grayImg. The returned matrix grayImg contains values in the range 0.0 (black) to 1.0 (full intensity or white).

    0 讨论(0)
  • 2020-12-05 19:28

    imhist displays a histogram of a grayscale or binary images. Use rgb2gray on the image, or use imhist(input(:,:,1)) to see one of the channel at a time (red in this example).

    Alternatively you can do this:

    hist(reshape(input,[],3),1:max(input(:))); 
    colormap([1 0 0; 0 1 0; 0 0 1]);
    

    to show the 3 channels simultaneously...

    0 讨论(0)
  • 2020-12-05 19:33

    Histogram is useful to analyze pixel distribution in an image. Histogram plots number of pixel in an image with respect to intensity value.

    img1=imread('image.jpg');
    hist(img1);
    
    0 讨论(0)
  • 2020-12-05 19:41

    I pefere to plot the histogram for Red, Green and Blue in one plot:

    %Split into RGB Channels
    Red = image(:,:,1);
    Green = image(:,:,2);
    Blue = image(:,:,3);
    
    %Get histValues for each channel
    [yRed, x] = imhist(Red);
    [yGreen, x] = imhist(Green);
    [yBlue, x] = imhist(Blue);
    
    %Plot them together in one plot
    plot(x, yRed, 'Red', x, yGreen, 'Green', x, yBlue, 'Blue');
    
    0 讨论(0)
  • 2020-12-05 19:42

    An histogarm plot will have number of pixels for the intensity levels. Yours is an rgb image. So you first need to convert it to an intensity image.

    The code here will be:

    input = imread ('sample.jpeg');
    
    input=rgb2gray(input);
    
    imhist(input);
    
    imshow(input);
    

    You will be able to get the histogram of the image.

    0 讨论(0)
提交回复
热议问题