occupancy detection from a column of zeros and ones
조회 수: 2 (최근 30일)
이전 댓글 표시
Hello All,
I have some data which is basically some 0s and 1s like below in one column:
1
1
1
0
1
0
0
0
1
0
1
1
1
1
1
1
0
0
1
1
1
1
1
0
0
0
1
0
1
1
0
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0
0
1
1
1
1
1
1
1
1
1
0
1
0
0
1
0
1
0
1
1
1
0
0
1
0
0
0
1
1
0
0
1
0
1
1
1
1
0
1
1
1
1
0
0
1
0
0
0
0
These show occupancy status of a location. When it is zero it means that the place is unoccupied, and when it is 1 it means that the place is occupied. The problem is that these data are not accurate. So the location is occupied if and only if there are at least 3 consecutive 1s happening, and it is unoccupied it there are at least 3 consecutive zeros happening. Can you please tell me how I can identify occupancy and non-occupancy data using this criteria? Thanks, Masih
댓글 수: 0
채택된 답변
Image Analyst
2017년 6월 6일
Use bwareaopen() or bwareafilt(). Both are in the Image Processing Toolbox.
occupancy = [...
1
1
1
0
1
0
0
0
1
0
1
1
1
1
1
1
0
0
1
1
1
1
1
0
0
0
1
0
1
1
0
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0
0
1
1
1
1
1
1
1
1
1
0
1
0
0
1
0
1
0
1
1
1
0
0
1
0
0
0
1
1
0
0
1
0
1
1
1
1
0
1
1
1
1
0
0
1
0
0
0
0]
% Get rid of regions 2 or less, leaving occupied elements only.
occupancy = bwareaopen(occupancy, 3)
% The inverse is the non occupied elements.
nonOccupied = ~occupancy
댓글 수: 3
Image Analyst
2017년 6월 7일
In a way, it does. That's what occupancy is. You can pass it into find if you want to convert to indexes
indexes = find(occupancy)
If you want it to say exactly "Region n goes from i1 to i2" then use this code:
% Get rid of regions 2 or less, leaving occupied elements only.
occupancy = bwareaopen(occupancy, 3)
% The inverse is the non occupied elements.
nonOccupied = ~occupancy
indexes = find(occupancy)
[bw, numRegions] = bwlabel(occupancy)
props = regionprops(bw, 'PixelList');
for p = 1 : numRegions
thisRegion = props(p).PixelList(:, 2);
fprintf('Region %d goes from element %d to element %d\n', ...
p, thisRegion(1), thisRegion(end));
end
and you'll see it print out:
Region 1 goes from element 1 to element 3
Region 2 goes from element 11 to element 16
Region 3 goes from element 19 to element 23
Region 4 goes from element 32 to element 49
Region 5 goes from element 52 to element 60
Region 6 goes from element 69 to element 71
Region 7 goes from element 84 to element 87
Region 8 goes from element 89 to element 92
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!