function J = myhisteq(I)
[rows, cols, colors] = size(I);

% Debugging values
%fprintf('rows: %f\n', rows);
%fprintf('cols: %f\n', cols);

% Set output to current image
J = I;

% Convert RGB to HSV
image_HSV = rgb2hsv(I);
%imshow(image_HSV(:,:,3));

% Init hist to zeros
H = zeros(256,1);

% Iterate through all pixel locations
for row=1:rows
    for col=1:cols
        index = ceil(image_HSV(row, col, 3) * 255) + 1;
        H(index, 1) = H(index, 1) + 1;
    end
end

% Verify the histogram worked
%plot(H);

% Init and calc. the cumulative histogram
C = zeros(256,1);

for row=1:256
   C(row, 1) = sum(H(1:row, 1));
end

% Verify cumulative curve
%plot(C);

% Iterate through all pixel locations and transform
for row=1:rows
    for col=1:cols
        index = ceil(image_HSV(row, col, 3) * 255) + 1;
        image_HSV(row, col, 3) = (255/(rows * cols)) * C(index, 1) / 255;
    end
end

J = hsv2rgb(image_HSV);

end