-4

I have a binary image with 4 blobs. 3 of them has an aspect ratio of more than 1. and 1 has aspect ratio of 1. Now I want to reduce that blobs which aspect ratio more than 1 in binary image. How could i do this. Can some one please provide a code??

Here is a link of the binary image. I want to reduce that 3 blobs which has an aspect ratio more than 1. And only want to keep that triangle shape.

https://www.dropbox.com/s/mngjlcsin46fgim/demo.png?dl=0

tkruse
  • 10,222
  • 7
  • 53
  • 80
Dominic
  • 47
  • 5

1 Answers1

0

you can use regionprops for that , for example:

 s=regionprops(bw,'BoundingBox','PixelIdxList');

where bw is your binary image.

The output of s.BoundingBox is a [x,y,width,height] vector you can loop over s

for i=1:numel(s)
    ar(i) = s(i).BoundingBox(3)/s(i).BoundingBox(4)          
end

and see if the width/height ratio ar (or whatever you define aspect ratio) is approx above 1 or not (because of noise I'd take a value of ar>1.2) . Then for that i use you can use the pixel list s(i).PixelIdxList

 bw(s(ar>1.2).PixelIdxList)=0; 

to zero these intensities...

bla
  • 25,846
  • 10
  • 70
  • 101
  • But is it possible to use that **pixelList** in vision.BlobAnalysis. To set pixel values to zero. I have applied another approach that is related to vision.blobAnalysis. I extracted all ROI and calculated their aspect ratio than applied condition _if AspectRatio = 1_ than insert a shape(rectangle) . But other blob remains in the output image. Now i want to set zero to pixelList of those blobs that are not satisfying above condition. And i am now stuck here. – Dominic Jul 18 '17 at 09:43
  • https://www.mathworks.com/examples/matlab-computer-vision/mw/vision_product-OCRExample-recognize-text-using-optical-character-recognition-ocr?s_tid=srchtitle in this documentation i have used following section- **ROI-based Processing To Improve Results** – Dominic Jul 18 '17 at 09:50