Results 1 to 2 of 2

Math Help - [Matlab] Constructing a 3d histogram from a picture

  1. #1
    Member
    Joined
    Mar 2010
    Posts
    96

    Question [Matlab] Constructing a 3d histogram from a picture

    I wrote a function for constructing histogram for an arbitrary picture. It reads only R (red) and G(green) channel.
    Code:
    function H = myhistogram2RG(img1, bins)
        %Here you make eqaul distribution for the pixels
        img1 = floor(double(img1)*(bins) / 255 ) + 1 ;
        %Matrice bins * bins all of zeroes
        H = zeros(bins, bins);
        for i=1:size(img1, 1)
            for j = 1:size(img1, 2)
                R = img1(i,j,1);
                G = img1(i,j,2);
                %When the pixel is the right colour add one to corresponding
                %element in the matrice
                H(R,G) = H(R,G) + 1;
            end
        end
        %Normalization
        H = H / sum(sum(H));
    end
    When I read a picture with imread command, and I call a function with myhistogram2RG(image,10) I get an error.
    Code:
    Attempted to access H(11,8); index out of bounds because
    size(H)=[10,10].
    I don't understand why isn't working. Thank you for your help.
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Super Member Rebesques's Avatar
    Joined
    Jul 2005
    From
    At my house.
    Posts
    538
    Thanks
    11

    Re: [Matlab] Constructing a 3d histogram from a picture

    bins=10< size(image,1)
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Histogram help
    Posted in the Statistics Forum
    Replies: 1
    Last Post: July 8th 2010, 03:03 PM
  2. mean from a histogram
    Posted in the Statistics Forum
    Replies: 1
    Last Post: March 31st 2010, 10:57 AM
  3. histogram please help!?
    Posted in the Algebra Forum
    Replies: 3
    Last Post: March 2nd 2008, 08:44 AM
  4. Histogram help please!
    Posted in the Statistics Forum
    Replies: 1
    Last Post: June 10th 2007, 07:10 AM
  5. Histogram Help
    Posted in the Statistics Forum
    Replies: 1
    Last Post: April 1st 2007, 12:38 AM

Search Tags


/mathhelpforum @mathhelpforum