How can I extract the rectangular shapes form the binary images without using bwareaopen function?

4 ビュー (過去 30 日間)
Hello every one,
Could you please help me, how to automatically extract the rectangular object in the following two images? I used bwareaopen function to remove small objects, but it sometimes removes the region of interest because the noisy objects are bigger than the number plate.
  3 件のコメント
Selva Karna
Selva Karna 2021 年 3 月 4 日
編集済み: Selva Karna 2021 年 3 月 4 日
from Python Code;
Code :
Main code 1 :
import cv2
import numpy as np
import os
im = cv2.imread('input1.jpg')
imgray = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
ret, thresh = cv2.threshold(imgray, 220, 255, 0)
edges = cv2.Canny(thresh,150,180,apertureSize = 3)
ret, labels = cv2.connectedComponents(~thresh)
x=0
[m,n]=np.shape(thresh)
c=1
cwd = os.getcwd()
msk=np.zeros(np.shape(thresh))
while c
msk=np.zeros(np.shape(thresh))
msk[(labels==c)]=[255]
msk=np.array(msk,dtype=np.uint8)
msk_img=str(c)+'.jpg'
filename = os.path.join(cwd, msk_img)
cv2.imwrite(filename,msk)
c=c+1
print("Total Polygon Objects ", c)
Javid Hamdard
Javid Hamdard 2021 年 3 月 4 日
Dear Selva Karna, thank you very much. I have applied the MATLAB code but still it dose not work.

サインインしてコメントする。

回答 (1 件)

Keerthana Chiruvolu
Keerthana Chiruvolu 2021 年 3 月 7 日
Hi Javid,
One simple method would be to use the Image Segmenter App where you can draw the region of interest and extract it from the image.
  1 件のコメント
Javid Hamdard
Javid Hamdard 2021 年 3 月 7 日
Dear Keerthana Chiruvolu, I think the Image Segmenter app will not solve the problem because my interest region will be in a different location. For example, the front or rear of the car or image may be taken from varying angles. Therefore, I look for a method that can automatically find the number plate area in the image.

サインインしてコメントする。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by