0
votes

I have a set of images classified as good quality image and bad quality image. I have to train a classification model so that any new image can be classified as good/bad. SVM seems to be the best approach to do it. I have done image processing in MATLAB but not in python.

Can anyone suggest how to do it in python? What are the libraries? For SVM scikit is there, what about feature extraction of image and PCA?

3
Be careful the problem you are trying to deal with is not classification is quality evaluation. I am not expert in Python but from image processing point of view these are two different problems.Bashar Haddad
@BH85 I agree. But the problem is to evaluate the quality and on the basis of it classify if its bad or good. What is the right approach to do it?maggs

3 Answers

3
votes

I would start reading this simple tutorial and then move into the OpenCV tutorials for Python. Also, if you are familiar with the sklearn interface there is Scikit-Image.

2
votes

I am using opencv 2.4,python 2.7 and pycharm

SVM is a machine learning model for data classification.Opencv2.7 has pca and svm.The steps for building an image classifier using svm is

  1. Resize each image
  2. convert to gray scale
  3. find PCA
  4. flat that and append it to training list
  5. append labels to training labels

Sample code is

for file in listing1:
 img = cv2.imread(path1 + file)
 res=cv2.resize(img,(250,250))
 gray_image = cv2.cvtColor(res, cv2.COLOR_BGR2GRAY)
 xarr=np.squeeze(np.array(gray_image).astype(np.float32))
 m,v=cv2.PCACompute(xarr)
 arr= np.array(v)
 flat_arr= arr.ravel()
 training_set.append(flat_arr)
 training_labels.append(1)

Now Training

trainData=np.float32(training_set)
responses=np.float32(training_labels)
svm = cv2.SVM()
svm.train(trainData,responses, params=svm_params)
svm.save('svm_data.dat')

I think this will give you some idea.

1
votes

Take a look at dlib and opencv. Both are mature computer vision frameworks implemented in C++ with python bindings. That is important because it means it is relying on compiled code under the hood so it is significantly faster than if it was done in straight python. I believe the implementation of the SVM in dlib is based on more resent research at the moment so you may want to take that into consideration as you may get better results using it.