From: Lukáš Jiřiště Date: Mon, 19 Aug 2024 11:47:05 +0000 (+0200) Subject: Implement image mask computation and usecase X-Git-Url: https://git.ljiriste.work/?a=commitdiff_plain;h=80d41a01e9b1469dc5f20222a87f8e9dcde7d9a3;p=Bubble_column.git 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. --- 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 +