Ask Your Question
0

Image Classification

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

Raki gravatar image

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

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

Comments

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

gino0717 gravatar imagegino0717 ( 2019-01-15 23:08:26 -0600 )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 -0600 )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 -0600 )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 -0600 )edit
2

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 -0600 )edit
1

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

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

@Raki. Python or cpp?

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

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

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

@StevenPuttemans

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 -0600 )edit
1

@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 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
-1

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

supra56 gravatar image

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

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')
gray=cv.cvtColor(im,cv.COLOR_BGR2GRAY)
img = cv.medianBlur(gray,5)
cimg = cv.cvtColor(img,cv.COLOR_GRAY2BGR)
circles = cv.HoughCircles(img,cv.HOUGH_GRADIENT,
                          1,300,
                          param1=40,
                          param2=20,
                          minRadius=15,
                          maxRadius=30)
circles = np.uint16(np.around(circles))
for i in circles[0,:]:
    cv.circle(cimg,(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)
cv.waitKey(0)
cv.destroyAllWindows()

Output: hole

edit flag offensive delete link more

Comments

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 -0600 )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 -0600 )edit
2

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

StevenPuttemans gravatar imageStevenPuttemans ( 2019-01-18 03:19:31 -0600 )edit

Question Tools

1 follower

Stats

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

Seen: 651 times

Last updated: Jan 16 '19