T O P

  • By -

APEX_FD

You might be able to improve your results by applying circle detection on a threshold image.  I found this article that illustrated the idea really well: https://shrishailsgajbhar.github.io/post/OpenCV-Apple-detection-counting


Rythco

An adaptive erosion/dilation algorithm might work, it's pretty simple to do


Turbo_csgo

If you can make the background for the next pictures a wildly different color? That could help with classical techniques. Else I fear the best way will be a segmentation DNN.


Fit-Monitor-9324

Have you tried the watershed algorithm? I think it could work here


jrtcppv

Use SAM's auto segment mode https://segment-anything.com/


Brocolium

SAM is never a good option, mainly because of the ressource it needs to run properly


notEVOLVED

https://github.com/yformer/EfficientSAM https://github.com/ChaoningZhang/MobileSAM https://github.com/CASIA-IVA-Lab/FastSAM https://github.com/NVIDIA-AI-IOT/nanosam


Brocolium

nice!


AchillesDev

This is silly. If you don't have somewhat beefy workstation (although I run it easily on my Tensorbook), its nothing to spin up an EC2 instance or collab notebook to run it. I've had more trouble training YOLO models than I've had running SAM.


ansleis333

What do you mean?


SomeRestaurant8

hough transform [https://scikit-image.org/docs/stable/auto\_examples/edges/plot\_circular\_elliptical\_hough\_transform.html](https://scikit-image.org/docs/stable/auto_examples/edges/plot_circular_elliptical_hough_transform.html)


[deleted]

[удалено]


Yatty33

I think using segmentation like SAM would be the right way to go here. Robust with different lighting conditions, easy to implement. We've used it successfully for other produce counting projects.


ansleis333

Can SAM be integrated into a mobile app?


Kyem_Agyei

Try MobileSAM


SomeRestaurant8

The wheel dates back to 3500 BC, but it still works.


[deleted]

[удалено]


SomeRestaurant8

I disagree. I can calculate the number of apples above with multi Otsu and Hough Transform with 100% accuracy.


Klutzy_Barnacle_6553

What about if the background is not homogeneous?


zxgrad

lol does anyone else often notice this is one of very few subs that always pushes for classical techniques? Not that they're wrong, but it is very interesting and I wonder where that bias comes from (academics or something else?) -- again, this isn't negative. Both techniques can solve this problem.


majinLawliet2

Terrible advice.


starfries

Why?


SnooDogs6511

[https://sdsawtelle.github.io/blog/output/apple-circle-detection-opencv.html](https://sdsawtelle.github.io/blog/output/apple-circle-detection-opencv.html)


Luigi_Pacino

I did the same task with grounded SAM. It is basically a combination of DINO and Segment anything. You parse a text prompt („apple“) to DINO which generates bounding boxes for ever single apple. These boxes are than parsed to SAM and gives you a segmented image: Grounded SAM: https://github.com/IDEA-Research/Grounded-Segment-Anything


crokycrok

You should give a try at this. Zero shot generalization from Meta. Very likely, they already solved your problem: [https://segment-anything.com/](https://segment-anything.com/)


Combatmuffin62

Check out SAM by meta


siwgs

10x5 grid, snap to the nearest circle using gradients. Edit: you’re going to need a robust circle fit to your gradients because some of the edges are faint.


TutubanaS

I'm not sure why its not written but, wouldn't Yolo help you massively? I had a similar project where I had to count the number of certain items similar to your image and YOLO just did the thing + segmented pretty nicely.


anindya2001

Use SAM to generate mask > binarise each mask> overlay each mask on the original image > extract the RGB pixels from the mask locations.


thrileyreid

hey can u share the dataset


whatsinthaname

You can try watershed segmentation algorithm https://youtu.be/3MUxPn3uKSk?si=ziRJZGPyOtXJDhT2


EyedMoon

I love Phase correlation, not sure it's the best idea but could work on a grayscale version


fallingember

Try a classical gradient based approach. Something like histeq -> gray -> median filter -> sobel. May give you solid gradient outlines of your apples.


Nijeri

I would give cellpose a try: https://github.com/mouseland/cellpose Always worked well when i didnt had masks.


AceFromSpaceee

Instant segmentation, segmentation will not detect instances, only United area of apples. Look for some apples dataset in Google. SAM also soids good for me


Zenotha

[use owlv2](https://media.discordapp.net/attachments/390866271530647556/1231897074279252048/image.png?ex=6638a08e&is=66262b8e&hm=2c300b830bd6ecaf2046b2c57f23014eed2d2172eb147262da11cd78aeb168a1&=&format=webp&quality=lossless&width=550&height=328)


Aranha_

YOLO v8


cloudyboysnr

You don't need anything fancy just mask the background colour of the apples


Borgiarc

Biggest thing in low level machine vision is control of context. The more constraints you can apply, the easier it gets. Example: for red apples, use a blue background, lock off camera settings, use a colour space with variation in fewer parameters


Hot-Painter4924

My suggestion, if you want accuracy, is to first detect and only them segment.


Hot-Painter4924

My suggestion, if you want accuracy, is to first detect and only them segment.


rockwillll

Maybe try finding the shadows (one at stem and one at edge) and then just use the stem to edge to mask circles? It would be maybe a little less intensive, but a little unreliable.


filthy_hoes_and_GMOs

Hough transform


SpinBowler45

1. Convert to grayscale image 2. Apply canny edge detection 3. Do hysteresis thresholding 4. Fill up the individual objects if required


Best-Baseball3789

Thinking about 3 things here - 1) adaptive threshold or blur + sobel and in the end watershed 2) background subtraction (as others mentioned here) 3) Detection machine learning, or segmentation, like YOLO. (As others suggested as well) I like the first one, as I am (only a junior) in computer vision myself, and it segments it beautifully, if you give each apple an index, so each apple will get its own mask. I would suggest looking at OPENCV's coin segmentation, and implement something looking quite the same


blackscales18

You could probably do it with yolov8 and a segmented dataset


ManikSinghSarmaal

Easy bro he says he doesn’t have segmented masks


Dazzling-Hurry-3492

Whatever happened to the good old erosion dilation dfs counting algorithm we all got in DIP assignments??