# Can an Integral Image assist in producing histograms?

I am reading 'OpenCV Computer Vision Application Programming Cookbook, 2nd Edition' and it teaches integral images. I understand the concept that an integral image allows us to calculate the mean of ROI's very efficiently - we just calculate the integral image first then whenever we want to know the mean for a given ROI we just need to perform 4 calculations (the 4 corners of the ROI) to obtain the mean rather than sum all pixels in the ROI and divide by the number of pixels.

However, in the book there is a sentence that I don't quite understand (see the bold one below).

We have also seen that sometimes, we are only interested in computing our histogram in a certain area of the image. In fact, having to cumulate a sum of pixels inside an image’s subregion is a common task in many computer vision algorithms.

Now, suppose you have to compute several such histograms over multiple regions of interest inside your image.All these computations could rapidly become very costly. In such a situation, there is a tool that can drastically improve the efficiency of counting pixels over image subregions: the integral image.

Does this mean integrals images can somehow produce histograms more efficiently? What is this relationship between integral images and histograms? Is it simply, you can use inspect histogram to obtain the mean of an ROI but you can also use an integral image (II) to obtain the mean of an ROI (and an II is more efficient). A histogram has other uses (not just finding the mean); we can find the min value, max value, standard deviation, local maximas/minimas. Does the integral image offer this sort of information aswell or just the mean?

Where did you find about: "considering only the 4 corners of an ROI to calculate the mean?"

@Zirihttps://docs.opencv.org/3.4/d7/d1b/gr...

(to be exact, we can calculate the

sumfrom the 4 corners, and knowing the area, the mean later)That makes sense now.

@sazr, histograms of

what? (i don't see the connection) .also it would need some explanation, why you're after the "mean".