I computed histogram using vImageHistogramCalculation_ARGB8888(...). I now have histogram data for each of the three RGB channels stored in 256 bins. My questions is what's the way to plot these values in a UIView using OpenGLES or Core Graphics? It needs to be done in real time (at least 30 frames per second).
Asked
Active
Viewed 332 times
1
-
This code from 2016 _may_ help: flexmonkey.blogspot.co.uk/2016/05/a-histogram-display-component-in-swift.html – Flex Monkey Feb 05 '18 at 21:25
-
I saw that code, but the problem is it draws three layers of RGB histograms separately without mixing. What's the way to draw by mixing colors of overlapping layers? – Deepak Sharma Feb 06 '18 at 09:10
1 Answers
1
You could do either. Neither approach is likely to be a problem at 30 frames a second.
Core Graphics is easier, so I'd start out by creating a custom subclass of UIView and overriding the draw(_:)
method.
In that method you could use UIBezierPath or CGPath to draw a series of rectangles the represent the bars of your histogram.
Give it a shot and report back if you get stuck.

Duncan C
- 128,072
- 22
- 173
- 272
-
How do I mix colors of the three RGB layers if I use UIBezierPath or CGPath? – Deepak Sharma Feb 06 '18 at 09:51
-
You will have to create a separate path for each colored band in your output. – Duncan C Feb 06 '18 at 16:34
-
I used UIBezierPath and it works but not upto my needs. I am not trying OpenGLES. Question is what is the best way to repeatedly pass the 256x1 histogram data to the shaders? – Deepak Sharma Feb 09 '18 at 18:31
-
-
Yes, because I want to merge colors which are overlapping. I don't see how to do that using draw(_:) – Deepak Sharma Feb 10 '18 at 06:36
-
It depends. If all you want is for the red, green, and blue graphs to show through each other, you could just make each one partly transparent. You haven't described the effect you're after so it's hard to help you achieve it. – Duncan C Feb 10 '18 at 12:38
-
If at point (x,y) you have red and green intensities present but not blue, I want to show yellow (=0xFFFF00). – Deepak Sharma Feb 10 '18 at 16:52
-
I give up, unable to create histogram with smooth curves that also blends different layers. – Deepak Sharma Feb 13 '18 at 13:33