From 80d41a01e9b1469dc5f20222a87f8e9dcde7d9a3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Luk=C3=A1=C5=A1=20Ji=C5=99i=C5=A1t=C4=9B?= Date: Mon, 19 Aug 2024 13:47:05 +0200 Subject: [PATCH] Implement image mask computation and usecase The mask is useful to filter the regions that are not interesting, that could make further processing more difficult. --- Bubliny.m | 6 ++++++ clean_mask.m | 19 +++++++++++++++++++ get_mask.m | 14 ++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 clean_mask.m create mode 100644 get_mask.m diff --git a/Bubliny.m b/Bubliny.m index 0f8f3f5..a2f26fa 100755 --- a/Bubliny.m +++ b/Bubliny.m @@ -110,4 +110,10 @@ for iii=1:nSelectedDirectory % Cycles for directories with files title('Difference between max and min'); imshow(changefig); + mask = get_mask(changefig, meanfig); + figure + imshow(meanfig .* uint8(mask)); + figure + plot(mean(double(meanfig), Weights = mask)); + end % iii, Cycles for directories with files diff --git a/clean_mask.m b/clean_mask.m new file mode 100644 index 0000000..29edf46 --- /dev/null +++ b/clean_mask.m @@ -0,0 +1,19 @@ +function mask = clean_mask(mask, strength) + if nargin < 2 + strength = 8; + end + kernel = [1 1 1; 1 1 1; 1 1 1]; + mask = 1 - mask; + for i = 1:strength + mask = conv2(mask, kernel, 'same') > 0; + end + mask = 1 - mask; + for i = 1:2*strength + mask = conv2(mask, kernel, 'same') > 0; + end + mask = 1 - mask; + for i = 1:strength + mask = conv2(mask, kernel, 'same') > 0; + end + mask = 1 - mask; +end diff --git a/get_mask.m b/get_mask.m new file mode 100644 index 0000000..28232d9 --- /dev/null +++ b/get_mask.m @@ -0,0 +1,14 @@ +function mask = get_mask(changefig, meanfig, threshold, strength) + if nargin < 3 + threshold = 200; + end + + mask = (changefig > threshold); + if nargin >= 4 + mask = clean_mask(mask, strength); + else + mask = clean_mask(mask); + end + mask = double(mask); +end + -- 2.30.2