Monday 16 May 2016

A Histogram Display Component in Swift for iOS






by Sarang Nagmote



Category - Mobile Apps Development
More Information & Updates Available at: http://http://vibranttechnologies.co.in




While Im writing some new content for Core Image for Swift discussing histograms, Ive found Core Images own histogram display filters slightly wanting. Always eager for a challenge, I thought Id write my own component for displaying histograms and plug it into Filterpedia. The component has no dependencies on Filterpedia, so can easily be reused in any other projects. 
The component is named HistogramDisplay and uses vImage to calculate the histogram data for a given CGImage. The histogram data consists of four arrays (one array for each color channel) of 256 unsigned integers - each containing the number of pixels in the image with that particular value. 
With that data, I use my Hermite smoothed drawing code to create Bezier paths for the three color channels (ignoring alpha) and simply use those paths to draw onto CAShapeLayers. 
The vertical scale is based on the maximum pixel count for any color / tone "bucket". Since there are occasionally outliers that make the scaling a bit crazy, my component allows the user to set the vertical scale with a touch gesture. 
To open the histogram display as a popover in Filterpedia, toggle the UISwitch in the top right corner of the user interface:


Maybe not the most elegant user interface solution, but working for my immediate requirements. 

No comments:

Post a Comment