From: Lukáš Jiřiště Date: Mon, 14 Oct 2024 09:10:47 +0000 (+0200) Subject: Create separate script for mask creation X-Git-Url: https://git.ljiriste.work/?a=commitdiff_plain;h=021da9c8929eeaca0d52c9c6906b1ede92d709e7;p=Bubble_column.git Create separate script for mask creation The script create_mask saves the mask as P4 NetPBM (binary BitMap) which is then loaded in the main script (Bubliny.m) --- diff --git a/Bubliny.m b/Bubliny.m index e623cf6..43cbd46 100755 --- a/Bubliny.m +++ b/Bubliny.m @@ -1,8 +1,6 @@ close all; clear all; -%% vstupni data T:\00-Orvalho\Travnickova\Bubble column - % User dialog for the data directory used for files DirectoryName = get_data_dir(); @@ -35,20 +33,27 @@ end ResFile = [res_path, ResFile]; %} +mask = load_mask(); + FileType = '*.png'; -main_wb = waitbar(0, 'Whole processing progress'); % process all directories in cycles for i=1:nSelectedDirectory FileName=([DirectoryName '/' SelectedDirectory{i} '/' FileType]); FFiles = dir(FileName); % Loads files to struct FFiles(1).name, FFiles(1).folder, FFiles(1).date - i s casem - %%D_num=str2double(SelectedDirectory{i}(21)); % position of camera [minfig, maxfig, meanfig] = get_aggregate_images(FFiles); - changefig = maxfig - minfig; - mask = get_mask(changefig, meanfig); - figure(); - imshow(meanfig .* uint8(mask)); + + if (i == 1) + figure(); + imshow(meanfig .* uint8(mask)); + mn = menu('May the computation proceed with this mask?', 'Yes', 'No'); + if (mn == 2) + close all + return + end + main_wb = waitbar(0, 'Whole processing progress'); + end waitbar((i - 0.5)/nSelectedDirectory, main_wb); diff --git a/create_mask.m b/create_mask.m new file mode 100644 index 0000000..050edc6 --- /dev/null +++ b/create_mask.m @@ -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 index 0000000..d5bae4b --- /dev/null +++ b/load_mask.m @@ -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