Implement image mask computation and usecase
authorLukáš Jiřiště <jiriste@icpf.cas.cz>
Mon, 19 Aug 2024 11:47:05 +0000 (13:47 +0200)
committerLukáš Jiřiště <jiriste@icpf.cas.cz>
Mon, 19 Aug 2024 12:51:34 +0000 (14:51 +0200)
The mask is useful to filter the regions that are not interesting,
that could make further processing more difficult.

Bubliny.m
clean_mask.m [new file with mode: 0644]
get_mask.m [new file with mode: 0644]

index 0f8f3f569fdf97cf3c7510d9d2dc0e3b98d74471..a2f26fa52ed99fa4308c6a3215b1e7a2ad658e10 100755 (executable)
--- 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');\r
        imshow(changefig);\r
 \r
+       mask = get_mask(changefig, meanfig);\r
+       figure\r
+       imshow(meanfig .* uint8(mask));\r
+       figure\r
+       plot(mean(double(meanfig), Weights = mask));\r
+\r
 end  % iii, Cycles for directories with files\r
diff --git a/clean_mask.m b/clean_mask.m
new file mode 100644 (file)
index 0000000..29edf46
--- /dev/null
@@ -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 (file)
index 0000000..28232d9
--- /dev/null
@@ -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
+