0

Little description:
I get an image from my scanner using Capture Core Framework and background color is gray. So I want to do white background.

I'm looking for best way to remove this color. I looked at Image Core Filters. And as I understood I should use those ones, but I couldn't find included/ready filterfor this task. So, Do I have to write it myself?
It means to remove color I should write my own filter and apply it to my images? Right? Thank you.

UPD: I develop for Mac os

James
  • 523
  • 4
  • 19
  • 1
    I don't know if there is any sdk supported way. Have you read about Core Image framework in iOS? If nothing native is there, and if you decided to do it on your own, then my answer on [this](http://stackoverflow.com/questions/7171679/want-to-change-a-particular-color-inside-an-image-with-another-color-iphone/7172066#7172066) thread might be helpful. – Krishnabhadra Jan 22 '13 at 04:41
  • Thak for your answer. I couldn't find, I think there's nothing native in mac os sdk... But in your example as I understood you just change color to another. But in my case I will have to analyze areas, cause color what I want to delete can place on the sheet what I scanned. – James Jan 22 '13 at 04:53
  • I agree, that is why I just said that my answer there will be helpful, instead of my answer will answer your question. You will have to do some pattern matching or something to find areas where to change color. – Krishnabhadra Jan 22 '13 at 05:18

2 Answers2

1

A filter isn't quite the right tool for the job here. Filters apply a colour-shifting algorithm, pixel by pixel, to all of the pixels in an image.

This would be appropriate in your case if there was something completely unique about the pixels that you want to turn to white. For example, if the background you wish to eliminate was in a very narrow colour range that did not occur in any other part of the image. This is the technique used in greenscreen/bluescreen filming, which only works if that green or blue colour does not occur anywhere in the image regions you want to keep.

But - as you say in one of your comments - you cannot do this as that grey level you want to get rid of will not be unique to the background, so any filter you apply that would pick out those pixes may also affect pixels in the scanned subjectmatter.

What you really need is a way to select a region of interest and apply a filter to that region alone. You could use openCV for this. In fact it has a function that can achieve your result in one go:

http://docs.opencv.org/modules/imgproc/doc/miscellaneous_transformations.html?highlight=floodfill#int

floodFill(InputOutputArray image, //image to process
          Point seedPoint,        //starting pixel
          Scalar newVal,          //New value of the repainted domain pixels
          Rect* rect,             //optional output param (you won't need it)
          Scalar loDiff,          //max lower brightness/colour diff to select
          Scalar upDiff,          //max upper brightness/colour diff to select
          int flags)              //you want FLOODFILL_FIXED_RANGE

This function starts from a seedPoint, which should be any pixel that you can guarantee will be a part of the background grey you want to eliminate. (0,0) might work for you. It then interrogates neighbouring pixels, including them in the ROI array if they are sufficiently similar. The resulting array is a connected region. If your background grey uniformly falls between loDiff and upDiff - and your subject scan has a defined edge which does NOT fall into this range, you will get your result - selection and remapping of all background pixels to newVal (white).

foundry
  • 31,615
  • 9
  • 90
  • 125
  • Thank you. It's function like a magic wand in Photoshop. I thought to write something similar myself. I don't know what about Opencv. Cause it will increase size of my application. But I think I should compare sizes of application with my own filter and with opencv. – James Jan 23 '13 at 02:32
  • @АртёмИбрагимов, I would expect it is possible to make a really small build of openCV if you only need this function. I haven't tried this, but it should work. – foundry Jan 23 '13 at 05:15
1

Why not just simply change the brightness of your image? If this gray background color value is fixed then you can increase the brightness a little bit, as a preprocess step, until you're satisfied.

LovaBill
  • 5,107
  • 1
  • 24
  • 32