필터 지우기
필터 지우기

Proper use of regionprops

조회 수: 2 (최근 30일)
Matlabhelp
Matlabhelp 2016년 10월 4일
댓글: Rena Berman 2020년 10월 12일
Hello
I have data which consists of a 20x20 matrix. The data has been split into their own cells as shown by the code below. Im trying to use the regionprops command to identify patterns within each cell, whereas a pattern consists of a 3 row's of 1s. e.g 1-1-1. or a block of 1's, or a line of 1's vertically. How do i go about using this function to do it
numberLocations = cell(1,5);
for k = 1:5 numberLocations{k} = (roundData==k);
end
  댓글 수: 3
Matlabhelp
Matlabhelp 2016년 10월 4일
편집: Walter Roberson 2016년 10월 13일
If you are able to help with this then instead of regionprops. Using the same 20x20 matrix i have converted each value in that matrix to either a 1,2,3,4 or 5 from this code. Where as roundData = matrix and rangeValue1 changes the value into a 1 and rangeValue2 change the value into a 2 and so on.
roundData(roundData >= restrictRange4 & roundData <restrictRange5) = rangeValue5;
roundData(roundData > restrictRange3 & roundData <restrictRange4) = rangeValue4;
roundData(roundData >= restrictRange2 & roundData < restrictRange3) = rangeValue3;
roundData(roundData >= restrictRange1 & roundData <restrictRange2) = rangeValue2;
roundData(roundData > 0 & roundData < restrictRange1) = rangeValue1;
The other way i would've tried to find a pattern such as a row ( 1,1,1 or 2,2,2 ) is
For r = 1:MAX_COLUMNS
c = 1:MAX_COLUMNS
% mapValue is a certain cell in my array, (mapValue1 is row 1, column 1 and so on for the others)
mapValue1 = roundData(r,c)
mapValue2 = roundData(r+1,c)
mapValue3 = roundData(r+2,c)
If mapValue1 == mapValue2 == mapValue3
end
end
The problem i actually had with this code was displaying it on another array that is had found, after the IF i didn;t know how to store the newly found data. How do i do so?
Rena Berman
Rena Berman 2020년 10월 12일
(Answers Dev) Restored edit

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

답변 (2개)

Dimitris Iliou
Dimitris Iliou 2016년 10월 13일
If I understand correctly, you want to use regioprops in order to identify a ‘1-1-1’ pattern in your data.
Regionprops might not be the best workflow to use in order to identify the pattern.
I would like to suggest a different workflow that might be more quick and efficient for your case. Write a script that:
  1. Uses a 3x3 mask that has the ’1-1-1’ pattern in it (i.e. mask = [0 0 0; 1 1 1; 0 0 0];)
  2. ‘Slide’ the mask over your data and calculate the cross-correlation between the mask and the data at each point.
  3. If the cross-correlation result is 1 then you have found your pattern.
To estimate the cross-correlation you could use the xcorr command. You can find more details about xcorr and how to use it in the following documentation link:
The same process can be used if your mask is vertical line of 1’s or a block. You would only need to modify the mask block and then use xcorr as before.
  댓글 수: 1
Image Analyst
Image Analyst 2016년 10월 13일
편집: Image Analyst 2016년 10월 13일
I think you meant 3, not 1. Anyway, this is a common misconception. Other patterns could also give a correlation of 3, not only the desired pattern. See this demo to prove it to yourself:
format short g;
m=zeros(10);
template = [1, 1, 1]
m(3, 4:6) = template % Place horizontal pattern in location 1
m(5:7, 2) = template' % Place vertical pattern in location 2
m(7, 6) = 3 % Place pattern in location 3
% Do correlation and normalized cross correlation.
mCorr = xcorr2(m, template)

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


Image Analyst
Image Analyst 2016년 10월 13일
You want the hit or miss transform, bwhitmiss(). See this demo, which finds horizontal and vertical patterns of [1,1,1]:
format short g;
m=zeros(10);
template = [1, 1, 1]
m(3, 4:6) = template % Place horizontal pattern in location 1
m(5:7, 2) = template' % Place vertical pattern in location 2
m(7, 6) = 3 % Place pattern in location 3
hmHorizontal = bwhitmiss(m, template, [0,0,0])
hmVertical = bwhitmiss(m, template', [0,0,0])
output = hmHorizontal | hmVertical
When the template is centered over your pattern, you will have a 1, and you'll get zero where the pattern doesn't match perfectly.

카테고리

Help CenterFile Exchange에서 Correlation and Convolution에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by