How to remove rows from structure based on value condition of field?

5 ビュー (過去 30 日間)
Stan Wissink
Stan Wissink 2021 年 11 月 12 日
回答済み: Image Analyst 2021 年 11 月 12 日
Hi all,
In my structure class titled 'rawMeasurements' created by the function 'regionprops', I want to remove all rows with a value <10 from the first field called Area.
I tried this to start filtering out all the row's with a value of 1, but it doesn't seem to work and I'm guessing this isn't the best way to do this:
idx = ismember({rawMeasurements.Area}, {'1'});
rawMeasurements = rawMeasurements(~idx);
Does anyone know a way to fix this approach or come up with a new approach entirely?
If you need any additional info, please let me know.
Thank you!

採用された回答

Image Analyst
Image Analyst 2021 年 11 月 12 日
If you want a binary image with no blobs less than 10, call bwareaopen() before calling regionprops():
mask = bwareaopen(mask, 10); % Throw away blobs of 9 pixels or smaller.
rawMeasurements = regionprops(mask, 'Area');
allAreas = [rawMeasurements.Area]

その他の回答 (2 件)

KSSV
KSSV 2021 年 11 月 12 日
rawMeasurements.Area(rawMeasurements.Area<10) = []
  1 件のコメント
Stan Wissink
Stan Wissink 2021 年 11 月 12 日
Thank you for your answer!
Unfortunately, I get an error saying "Error using '<', too many input arguments."

サインインしてコメントする。


Awais Saeed
Awais Saeed 2021 年 11 月 12 日
S.A = [1 2 3 4 5 6; 11 12 13 14 15 16; 21 22 23 24 25 26; 31 32 1 34 35 36];
S.B = ceil(50*rand(2,2));
S.C = "Some string";
S.D = 3;
[rows,~] = find(S.A < 10);
rows = unique(rows);
S.A(rows,:) = [];

Community Treasure Hunt

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

Start Hunting!

Translated by