Making an image background white

I have several images like this and am trying to recognize objects using Neural Networks

and GIST

as functions. My dataset has 50 classes and 4 images for each class. Using 75% of the images as training data, I get a test accuracy of 83%

enter image description here

To be more precise, I want to preprocess the images. Ie I want to make the background transparent or white while keeping the original object. I try cv2.BackgroundSubtractorMOG2()

but it makes the whole image gray.

What would be the best way to preproject this image?

+3


source to share


3 answers


You can try using the GrabCut algorithm for this problem. Since you know that the subject is approximately in the center, you can try to plot the color distribution of the subject and collect background swatches from the edges of the image.

OpenCV documentation can be found here: http://docs.opencv.org/modules/imgproc/doc/miscellaneous_transformations.html#grabcut



with an example here: https://github.com/Itseez/opencv/blob/master/samples/cpp/grabcut.cpp

+1


source


You can try extracting outlines to find the object within the image. Then you can extract only that part of the image within the largest outline and assume that this is your object.



0


source


There is no better answer for image preprocessing. There are a number of things you can do to increase your training set / improve your classification accuracy. If you use neural networks (and especially train them yourself), you need to maximize your data in order to be most effective. Several possible methods you can follow to improve image preprocessing / dataset preparation:

  • Rotate your training images with arbitrary amounts (in addition to 90/180/270 degrees, roughly 30/60/120 / etc.).
  • Add gaussian noise randomly.
  • Color your images a little.
  • Reduce image.

Since you only have 4 images for each class, this is almost not enough training images, unless the images you want to classify are very similar to the images in your training set, so you want to rotate those 4 images (3 if you are using 75 % for training) to use something like 12 for training.

But for testing it is important to note that the SHAPE of the image is important. So if your network requires 50x50 image pixels and your original images are 100x50, you have several options for how to reshape the image to 50x50, including direct warping, cropping the 50x50 area from the middle, filling the image with black pixels to 100x100, and then rescaling. etc.

0


source







All Articles