Ask Your Question

Image Classification

asked 2019-01-15 07:28:42 -0500

Raki gravatar image

updated 2019-01-16 06:43:44 -0500

I am trying to classify two kinds of images as follows:

(1)image description

(2)image description

classes can be called unscrewable/screwable. The screwable ones(1) are the ones with a slot on them, in addition to the hole, whereas the unscrewable ones only contain a hole.

There are two ways of solving this problem.

  1. Train a network.
  2. Use edge information.

I tried to use sobel derivates and Canny but one can't implement something that works for all, I mean, anything that is threshold-dependent is not so reliable, I try to avoid using such methods, therefore. What works for these two images, does not work for more and etc. Perhaps sobel derivates weren't the best choice for this type, I don't know. Hence, my question.

I was curious if anyone here try to achieve something similar. The difference between these two classes are really little, and I wonder if it makes sense to use purely traditional image processing techniques found in OpenCV or to deploy a neural network. I suspect haar classifier wouldn't be able to tackle this either.

What do you think?

edit retag flag offensive close merge delete


I see the second image has many circle, maybe use hough circle detection?

gino0717 gravatar imagegino0717 ( 2019-01-15 23:08:26 -0500 )edit

There are neural nets in OpenCV also, and you can wrap quite alot of networks from other frameworks already. I would solve this with an easy classification setup. On the other hand, making a HOG and then feeding them to an SVM might already be working quite well.

StevenPuttemans gravatar imageStevenPuttemans ( 2019-01-16 05:05:12 -0500 )edit

@gino0717 I thought of that too, but not all of them have circles, sometimes it is just a hole without a slot. So hough circles don't work, It's my fault that I uploaded only that one, sorry.

Raki gravatar imageRaki ( 2019-01-16 05:17:59 -0500 )edit

@StevenPuttemans See my updated post, the images are really similar to each other, with only a slot being the difference. Which network in your opinion could really get the difference? Given around 50 images, let's say, of each class.

Raki gravatar imageRaki ( 2019-01-16 05:20:18 -0500 )edit

My first attempt would be a darknet48 network, pre-trained on imagenet, and passed those 50 samples to fine-tune the classifier. You could swap out the darknet48 structure easily by any network, just don't take a too deep one. These classification networks seem to capture quite smalle inner class differences fairly easy.

StevenPuttemans gravatar imageStevenPuttemans ( 2019-01-16 06:10:54 -0500 )edit

Thank you for your valuable input. I'll try it out and share the results.

Raki gravatar imageRaki ( 2019-01-16 06:12:35 -0500 )edit

@Raki. Python or cpp?

supra56 gravatar imagesupra56 ( 2019-01-16 06:38:33 -0500 )edit

Python3. Sorry, I am adding that to the question too.

Raki gravatar imageRaki ( 2019-01-16 06:43:31 -0500 )edit


What is a darknet48 network? Is it a yolov3 config stripped down to 48 layers and the weight were created using the partial command?

Or does it corresponds to the yolov3-tiny cfg?

I only found this one "darknet19_448.cfg" which is very very small indeed - smaller than tiny cfg

holger gravatar imageholger ( 2019-01-16 16:23:11 -0500 )edit

@holger, I think he means that one yes, that was the only I could find only as well

Raki gravatar imageRaki ( 2019-01-17 04:08:21 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2019-01-16 12:21:43 -0500

supra56 gravatar image

updated 2019-01-16 12:23:05 -0500

berak gravatar image

Your image #2 was too smaller 60x60. You had before was 256x256. There is nothing I couldn't do. Code:

#!usr/bin/env python3

import cv2 as cv
import numpy as np

im = cv.imread('holecan.png')
img = cv.medianBlur(gray,5)
cimg = cv.cvtColor(img,cv.COLOR_GRAY2BGR)
circles = cv.HoughCircles(img,cv.HOUGH_GRADIENT,
circles = np.uint16(np.around(circles))
for i in circles[0,:]:,(i[0],i[1]),2,(0,0,255),3)

im = cv.resize(cimg, (320, 240))
cv.imwrite('hole.jpg', cimg)
cv.imshow('detected circles',im)

Output: hole

edit flag offensive delete link more


supra, having a '*' in your (to be rendered as html) markdown is a problem. either use AxB or escape the whole A*b sequence using the "`" char

berak gravatar imageberak ( 2019-01-16 12:25:41 -0500 )edit

Both of the screws have holes/circles, how does this classify them? What we need to find is the slot line, which is the unique feature in class 1 (screwable).

Raki gravatar imageRaki ( 2019-01-17 04:09:04 -0500 )edit

i do not see how this solves the classification issue ...

StevenPuttemans gravatar imageStevenPuttemans ( 2019-01-18 03:19:31 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2019-01-15 07:28:42 -0500

Seen: 75 times

Last updated: Jan 16