Not sure if this is the right way to ask, but please help. I have an image of a rumpled car. I have to process it and extract the dents and return the number of dents. I was able to do this quite well with the following result:


Matlab code:
img2=rgb2gray(i1);
imshow(img2);
img3=imtophat(img2,strel('disk',15));
img4=imadjust(img3);
layer=img4(:,:,1);
img5=layer>100 & layer<250;
img6=imfill(img5,'holes');
img7=bwareaopen(img6,5);
[L,ans]=bwlabeln(img7);
imshow(img7);
I=imread(i1);
Ians=CarDentIdentification(I);
However, when I try to do this using opencv, I get the following:

With the following code:
Imgproc.cvtColor(source, middle, Imgproc.COLOR_RGB2GRAY);
Imgproc.equalizeHist(middle, middle);
Imgproc.threshold(middle, middle, 150, 255, Imgproc.THRESH_OTSU);
Please tell me how can I get the best results in opencv, as well as how to count dents? I tried findcontour (), but it gives a very large amount. I also tried on other images, but I do not get the proper results. Please, help.
source
share