Simplicity
Simplicity

Reputation: 48956

Shifting along the range of histogram values

Say that I have some image, for which I found the histogram. Say also that I have some equation that I want to calculate for each element in the histogram. How can I shift along the histogram values in MATLAB?

I have done the following:

I=imread('xyz.jpg');
h=imhist(I);
h(1) % get the value of the first element

In this way, to apply my equation, I used h(1) value for instance.

Is that right this way?

Thanks.

Upvotes: 0

Views: 846

Answers (1)

Eitan T
Eitan T

Reputation: 32930

If you want to iterate the histogram values, I suggest that you extract both outputs of imhist (I took the liberty to give them more expressive variable names):

[counts, bins] = imhist(I);

Arrays bins and counts contain the histogram bin locations and their counts, respectively. Then you can use a for loop:

res = zeros(numel(counts), 1); %// Preallocate array for the result
for k = 1:numel(counts)
    %// Apply equation on counts(k) and bins(k), for example:
    res(k) = some_equation(bins(k), counts(k));
end

or apply the equation in a vectorized form, if possible.

Upvotes: 1

Related Questions