I have two images of IRON RODS (i.e only two images) and I want to detect how many rods are there in each image and get the diameter of each rod in a image?

I don't know where to start as there are lot of articles regarding object detection and it's hard to find one for my use-case.

If you can help me with a abstract view on how to model such requirement? Please point me a right direction.


1) How can I train with two images and then how to count numbers of rods are there in each image and retrieve it's diameter?


Well to answer your last question, you cannot train with the images that you want to test your algorithm with, that is a paradox...

You will need more than just two images if you want to build a robust model that can detect each rod AND predict their diameter. Those are two different problems, and you might want to split your model in two branches: one to detect each rod, the other to predict its diameter as a regression problem.

If you can obtain a larger dataset with ground truth, then you can proceed to train your model. I would tend to say that using an object detector CNN would be overkill, but if you need to predict the diameter of each rod in the image, it might be necessary. So maybe look into TinyYOLO for the detection part, and then you could use the predict bounding box of each rod in the image for a small perceptron to infer the diameter.

  • $\begingroup$ So can I somehow use these two images to train to detect number of rods in a image and then predict it on a different image. I just need bounding box for each rod and then count number of rods. The thing is I'm not trying to build any robust model just a sample model and my three images are almost identical. $\endgroup$ Oct 16 '19 at 17:04
  • $\begingroup$ I don't want my model to predict any outside images. I only need it to perform well on those one of three images. $\endgroup$ Oct 16 '19 at 17:06
  • $\begingroup$ Yeah a deep learning approach is probably overkill for you problem. D.W.'s answer below is much more efficient. $\endgroup$ Oct 16 '19 at 17:10
  • $\begingroup$ It was mentioned in the exercise to use modern deep learning approach even though if it's a overkill. So can you help me out a little bit on this. I just want it to perform well on the three images I have.(a sample model) to predict number of rods and it's diameter. $\endgroup$ Oct 16 '19 at 17:11
  • $\begingroup$ Well first you need to annotate them. Then you can do some data augmentation (flip the images for example), cropping, padding... Once you have some sort of dataset, you can train a very simple object detector. It will surely overfit a lot but if you don't need to test it on a separate dataset then that's your solution. You can feed the bounding box coordinates of the CNN to an MLP to predict the diameter (since it's a linear problem it should be easy). $\endgroup$ Oct 16 '19 at 17:18

You might be able to solve your problem with classical image processing methods: binarize the image (to separate the black background from the rods), smooth with morphological operations, then use floodfill or connected components to identify each vertical black region. Each rod is a space between two vertical black regions, so you can then count the number of rods directly.

This assumes that all images look pretty similar to the example image you provided, and that there's not too much diversity in the images.

  • $\begingroup$ Thank you. I want to do it using modern convolution net rather than classical image processing methods. How can I achieve this? I don't want any complex model I just want it to perform well on those one of three almost identical images that I have. A sample model. $\endgroup$ Oct 16 '19 at 17:10
  • $\begingroup$ @Balachandar, why? It seems odd to come here and ask how to do it and then say "I don't like that answer". I can't find that requirement stated in your question. If you want to use cnns, there must be some requirement that classical image processing violates; I suggest figuring out what that is, and editing your question to make it explicit. $\endgroup$
    – D.W.
    Oct 16 '19 at 17:19
  • $\begingroup$ forget it. thank you so much for the answer. :) $\endgroup$ Oct 16 '19 at 17:21
  • $\begingroup$ @D.W. How can we get the diameter of each rod here using your approach? $\endgroup$
    – Sai Kumar
    Oct 17 '19 at 11:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.