MATLAB Answers

Hello everyone, I would like to ask that how to modify the following code. It includes bwlabel function and regionprops. I don't know where the code is wrong.

조회 수: 2(최근 30일)
Wesley
Wesley 2021년 5월 21일
댓글: Image Analyst 2021년 5월 27일
BW21=imread('m1.jpg');
%Step 1: Label each object using the following code.
ppp = imbinarize(BW21); % be sure your image is binary
L= bwlabel(ppp); % label each object
%Step 2: see the label of each object
s = regionprops(L,'Centroid');
imshow(ppp)
hold on
Code Analyzer has found a call of regionprops with a first argument that is a call to bwlabel. In many cases, the argument of bwlabel is a logical matrix, or you can convert it to one. Beginning in MATLAB Version 7.8 (release R2009a), you can pass this logical matrix directly to regionprops without the call to bwlabel. This is faster and uses less space than the previous method.
Suggested Action
If bw is a logical matrix, make the indicated change. If bw is not a logical matrix, convert it to a logical matrix, and then pass the converted matrix as the first argument to regionprops.
For example, if bw is a logical matrix, replace:
regionprops(bwlabel(bw), ...)
with:
regionprops(bw, ....)

채택된 답변

Image Analyst
Image Analyst 2021년 5월 21일
I wouldn't worry about it. You can pass in (the poorly-named) ppp if you want. But you still may want the labeled image because often you filter the blobs based on some criteria and to extract them, you can conveniently do it with ismember() if you have the labeled image. The time difference between using ppp or L will be unnoticeable in most cases.
  댓글 수: 3
Image Analyst
Image Analyst 2021년 5월 27일
@Tamara Ahmed OK. Looks like fun. Good luck. If you need help with it, post your questions and images in a new question (not here in Wesley's question) and study my Image Segmentation Tutorial.
You'll see how I differentiate coins types based on area. You'll do the same thing with your blobs to determine if it's a dot or dash. You'll want to threshold for dark things though, like
binaryImage = grayImage < someThreshold;
or use imbinarize() and invert it if you need to, to get the blobs to be white and background dark.

댓글을 달려면 로그인하십시오.

추가 답변(0개)

Community Treasure Hunt

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

Start Hunting!

Translated by