-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfind_images_mask.m
38 lines (31 loc) · 932 Bytes
/
find_images_mask.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
% read masks, find corresponding images, make them square size (512 xx 512)
clear
close all;
clc
mask_folder = 'dl_mask_test\masks';
im_folder = 'out';
im_sav_folder = 'dl_mask_test\images';
imds = imageDatastore(im_folder);
im_files = imds.Files;
imds_msk = imageDatastore(mask_folder);
msk_files = imds_msk.Files;
len = length(msk_files);
for i = 1:len
msk_spt = strsplit(msk_files{i,1},'\');
mask_name = msk_spt{end};
idx = find(contains(im_files,mask_name));
try
im_name = im_files{idx};
mask = imread(msk_files{i,1});
I = imread(im_name);
sz = size(mask);
[II,mm] = square_img_new(I,mask,512,1);
imshowpair(II,mm)
drawnow
imwrite(II,[im_sav_folder,'\',mask_name])
imwrite(mm,msk_files{i,1});
catch
delete(msk_files{i,1})
disp(['image ', num2str(i),' not found']);
end
end