Image Processing, OpenCV

how to convert images from one color-space to another in IOS using OpenCV !

In OpenCV all the image processing operations are usually carried out on the Mat structure. In iOS however, to render an image on screen it have to be an instance of the UIImage class. To convert an OpenCV Mat to an UIImage we use the Core Graphics framework available in iOS

how to convert images from one color-space to another, like BGR \leftrightarrow Gray, BGR \leftrightarrow HSV etc

 

Changing Color-space

There are more than 150 color-space conversion methods available in OpenCV. But we will look into only two which are most widely used ones, BGR \leftrightarrow Gray and BGR \leftrightarrow HSV.

For color conversion, we use the function cv2.cvtColor(input_image, flag) where flag determines the type of conversion.

For BGR \rightarrow Gray conversion we use the flags cv2.COLOR_BGR2GRAY. Similarly for BGR \rightarrow HSV, we use the flag cv2.COLOR_BGR2HSV.

 

 

 

After the processing we need to convert it back to UIImage. The code below can handle both gray-scale and color image conversions

 

After the processing we need to convert it back to UIImage.

Source: OpenCV

About mycodetips

Passionate about coding and software development holding 10+ Years of experience including 6+ years of experience on Mobile application Development.
View all posts by mycodetips →