Proper use of regionprops
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(2 个)
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:
- 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];)
- ‘Slide’ the mask over your data and calculate the cross-correlation between the mask and the data at each point.
- 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
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
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.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!