iOS how to mask the image background color
Asked Answered
W

1

1

I want to do following thing within in my iOS app:

  1. user can draw something on white background paper.
  2. my app allows user to capture the drawn image. Here the image will capture with background white color.
  3. finally from the captured image i need to mask the white background color and just get the image alone into UIImage object.

I completed the steps 1 and 2. But i do not have any idea how to do the last step. Is there any openCV library that i can use it with my iOS app?.

Any help that might be really appreciated.

Willettawillette answered 23/9, 2014 at 14:46 Comment(2)
how are you capturing the "user touch drawn"?Offload
In my case user not going to drawn the image on the phone screen directlyinstead he will drawn the image on white background color paper and my app will scan the image by using my iphone app.Willettawillette
H
1

Well, since OpenCV itself is THE library, I guess that you are looking for a way to do that with OpenCV.

  • First, convert the input image to Mat, which is the data type OpenCV uses to represent an image;
  • Then, assuming the background is white, threshold the Mat to separate the background from whatever the user draw. According to the example below, the result of this operation makes the background black, and every pixel that is not black will represent something the user has draw:

enter image description here

  • Finally, convert the resulting Mat to UIImage: for this, iterate on the Mat and copy every pixel that is not black to the UIImage to have an UIImage that contains only what the user draw.

A better idea is to iterate on the thresholded Mat, figure out which pixel is not black, and instead of copying it directly to the new UIImage, copy that pixel (x,y) from the original UIImage, so you have a colored pixel at the end, which gives a more realistic result.

Hind answered 23/9, 2014 at 21:49 Comment(2)
seems like your solution will work fine i guess let me try it out. Can you please point out the better library that will handle the above operation?. Or just using objective C i can achieve that?Willettawillette
Obj-C and OpenCV. This operation is easy to implement in Obj-C if you dont want to use an external library.Hind

© 2022 - 2024 — McMap. All rights reserved.