-
Notifications
You must be signed in to change notification settings - Fork 0
/
WIA1_createfolder.m
90 lines (74 loc) · 3.68 KB
/
WIA1_createfolder.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
%%%%%%%%%%%%%%
% This program opens images in a folder one by one, creates a folder
% for each image and allows user to choose ROI and polygon around wound
% boundary. The croped ROI image and polygon position, as well
% other infomation, will be saved in the corresponding folder.
%
% ---Xiang Mao, modified on Apr 4th, 2010---
%%%%%%%%%%%%%%
%%% get file
clear all
close all
clc
%Will: these varaibles need to be changed so they're not hard-coded but
%Will: actually inputs!
rootpath = 'C:\Documents and Settings\Xiang Mao\My Documents\MATLAB\'; %the path where images to be analyzed located
ImF = dir(fullfile([rootpath],'s*.jpg')); % the common part from titles of these images
n_ImF = size(ImF, 1);
for rr = 1:n_ImF
clear polygon*, clear Y*, clear ROI*;
imagepath = rootpath;
filename = ImF(rr).name;
if not(ImF(rr).isdir);
image_loaded = strcat(imagepath, filename);
filename = strrep(filename,'JPG','jpg');
filename_s = filename(1:(find(filename(:)=='.')-1));
savepath = [imagepath '\temporary save ',date,'\']; %Will: use pathsep or fullfile!
mName = char(mfilename) % the current running m file
plotpath = [savepath filename '\']; %Will: use pathsep!
mkdir(plotpath);
txtname = [mName,'_',date,'.txt']; % only save combined result, save to savepath
infoldertxt = [filename_s '.txt']; % save all information, save to specified folder for this image
Y = imread(image_loaded);
figure(1),imshow(Y); impixelinfo; title(filename);
%%% crop ROI, make sure wound in in center
s_cr = '';
while isempty(s_cr)
disp('Step 1: crop a region of interest (ROI) for wound');
disp('Click two points to define vertexes of a rectangluar that includes the entired wound region');
figure(1);imshow(Y); impixelinfo; title(filename);
[x,y] = ginput(2);
yc(1)=min(y);
yc(2)=max(y);
xc(1)=min(x);
xc(2)=max(x);
ROI = Y(yc(1):yc(2),xc(1):xc(2),:);
clear x, clear y; %Will: shouldn't use clear!
figure(1),clf,imshow(ROI);impixelinfo;title([filename '\_ROI']);
[M,N,O] = size(ROI);
%%% get center region position
clear ct %Will: shouldn't use clear!
ct = [round((yc(2)-yc(1))/2) round((xc(2)-xc(1))/2)];
cty = [ct(1)-round(M*0.10) ct(1)+round(M*0.10)];
ctx = [ct(2)-round(N*0.10) ct(2)+round(N*0.10)];
hold on
plot(ct(2),ct(1),'b*');
hold on,
plot(ctx(1):ctx(1),cty(1):cty(2),'g.',ctx(2):ctx(2),cty(1):cty(2),'g.',...
ctx(1):ctx(2),cty(1):cty(1),'g.',ctx(1):ctx(2),cty(2):cty(2),'g.');
disp('If satisfied with the centerbox postion, hit any letter follow by "enter" to continue');
s_cr = input('Otherwise, hit "enter" if you want to redo this step : \n','s');
imwrite(ROI, [ plotpath filename_s '_ROI.jpg']);
close all
end
%%% draw a polygon around wound region to create a skin model
disp('Step 2: draw a polygon around wound');
disp('The border of polygon should not cross any wound region.');
disp('Finish drawing the polygon by a double click.');
polygon = roipoly(ROI); %%% a logical mask
%%% save workspace
clear Y; %Will: shouldn't use clear!
save([plotpath filename_s]); %Will: use fullfile instead!
close all
end
end