필터 지우기
필터 지우기

occupancy detection from a column of zeros and ones

조회 수: 2 (최근 30일)
masih
masih 2017년 6월 6일
댓글: masih 2017년 6월 7일
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

채택된 답변

Image Analyst
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
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
masih
masih 2017년 6월 7일
Thanks a lot

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by