Ask Your Question
0

Remove black border lines around image after scan with opencv c++

asked Feb 17 '14

vsay gravatar image

updated Feb 17 '14

I have tiff images. After scan those images, there are long black lines around the the borders.

I manualy crop the image with increase x += 50; y += 50; width -= 100; heigth -= 100

With above approache, I can crop the images.

I want to ask if there is any way i could remove it autometically without tunning the parameters of x, y, width and heigth such as image enhancement?

Thank

EDITED

  • The image is grayscale image
  • There is only black and white color in the image so basically i would like to replace those black color with whit color
  • After scan the image there are long black pixel at the borders of the image and i want to remove that
Preview: (hide)

Comments

1

you probably meant: x += 50; y += 50; width -= 100; heigth -= 100

berak gravatar imageberak (Feb 17 '14)edit

2 answers

Sort by » oldest newest most voted
0

answered Feb 17 '14

Nghia gravatar image

updated Feb 17 '14

If you can determine the first border pixel accurately eg. occurs near (0,0) then you might be able to

  1. floodFill all black pixels starting at (0,0) or where ever, generate a binary image such that 0 is for border pixels, and 1 is for everything else
  2. use findContour + boundingRect to find the bounding box of the inside pixels. The findContour is very fast, it only visits pixels on the edge (not inside like a floodFill). findContour will return an array of possible contours, pick the largest one.
  3. crop the borders out using the bounding rect of the non-border pixels
Preview: (hide)
0

answered Feb 17 '14

updated Feb 17 '14

I would suggest running 4 nested loops on x,y, width, height and using the function countNonZero to count the number of white pixels. You can also take the negative image and use countNonZero to count the number of black pixels.

countNonZero:

http://docs.opencv.org/modules/core/doc/operations_on_arrays.html#countnonzero

negative image:

http://www.programming-techniques.com/2013/01/producing-nagative-of-grayscale-image-c.html

Preview: (hide)

Comments

well, 4 nested loops will affect my program's performances

vsay gravatar imagevsay (Feb 17 '14)edit

Question Tools

Stats

Asked: Feb 17 '14

Seen: 7,364 times

Last updated: Feb 17 '14