Create separate script for mask creation
authorLukáš Jiřiště <jiriste@icpf.cas.cz>
Mon, 14 Oct 2024 09:10:47 +0000 (11:10 +0200)
committerLukáš Jiřiště <jiriste@icpf.cas.cz>
Mon, 14 Oct 2024 09:10:47 +0000 (11:10 +0200)
The script create_mask saves the mask as P4 NetPBM (binary BitMap)
which is then loaded in the main script (Bubliny.m)

Bubliny.m
create_mask.m [new file with mode: 0644]
load_mask.m [new file with mode: 0644]

index e623cf6e6e1a05c1271045a350198c4389b6ef0d..43cbd464195227450b3c03fbe8677a8732c61009 100755 (executable)
--- a/Bubliny.m
+++ b/Bubliny.m
@@ -1,8 +1,6 @@
 close all;\r
 clear all;\r
 \r
-%% vstupni data T:\00-Orvalho\Travnickova\Bubble column\r
-\r
 % User dialog for the data directory used for files\r
 \r
 DirectoryName = get_data_dir();\r
@@ -35,20 +33,27 @@ end
 ResFile = [res_path, ResFile];\r
 %}\r
 \r
+mask = load_mask();\r
+\r
 FileType = '*.png';\r
 \r
-main_wb = waitbar(0, 'Whole processing progress');\r
 % process all directories in cycles\r
 for i=1:nSelectedDirectory\r
        FileName=([DirectoryName '/' SelectedDirectory{i} '/' FileType]);\r
        FFiles = dir(FileName);                                                 % Loads files to struct FFiles(1).name, FFiles(1).folder, FFiles(1).date - i s casem\r
 \r
-       %%D_num=str2double(SelectedDirectory{i}(21));                   % position of camera\r
        [minfig, maxfig, meanfig] = get_aggregate_images(FFiles);\r
-       changefig = maxfig - minfig;\r
-       mask = get_mask(changefig, meanfig);\r
-       figure();\r
-       imshow(meanfig .* uint8(mask));\r
+\r
+       if (i == 1)\r
+               figure();\r
+               imshow(meanfig .* uint8(mask));\r
+               mn = menu('May the computation proceed with this mask?', 'Yes', 'No');\r
+               if (mn == 2)\r
+                       close all\r
+                       return\r
+               end\r
+               main_wb = waitbar(0, 'Whole processing progress');\r
+       end\r
 \r
        waitbar((i - 0.5)/nSelectedDirectory, main_wb);\r
 \r
diff --git a/create_mask.m b/create_mask.m
new file mode 100644 (file)
index 0000000..050edc6
--- /dev/null
@@ -0,0 +1,21 @@
+clear all
+
+FileType = '*.png';
+
+last_path = get_last_path();
+[filenames, path] = uigetfile([last_path '/' FileType], ...
+       'Select all files for mask creation', 'MultiSelect', 'on');
+update_last_path(path);
+files = struct('name', cell(1, numel(filenames)), 'folder', cell(1,...
+numel(filenames)));
+[files.name] = deal(filenames{:});
+[files.folder] = deal(path);
+[minfig, maxfig, meanfig] = get_aggregate_images(files);
+changefig = maxfig - minfig;
+mask = get_mask(changefig, meanfig);
+figure();
+imshow(meanfig .* uint8(mask));
+[mask_file_name, mask_path] = uiputfile([path '/*.pbm'], 'Save you mask as...');
+if (mask_file_name ~= 0)
+       imwrite(mask, [mask_path '/' mask_file_name], 'PBM', 'Encoding', 'raw');
+end
diff --git a/load_mask.m b/load_mask.m
new file mode 100644 (file)
index 0000000..d5bae4b
--- /dev/null
@@ -0,0 +1,6 @@
+function mask = load_mask()
+       path = get_last_path();
+       [mask_file path] = uigetfile([path '/*.pbm'],...
+               'Select a mask for this batch');
+       mask = double(imread([path '/' mask_file]));
+end