-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetTheEyeCrop.m
More file actions
67 lines (59 loc) · 2.69 KB
/
getTheEyeCrop.m
File metadata and controls
67 lines (59 loc) · 2.69 KB
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
function crop = getTheEyeCrop(arguments)
% For the current dataset
%fprintf('>>> [INFO] Now Analyzing Top Folder: %s/%s ...\n', arguments.DATA_DIR, arguments.sortedTitle{arguments.topFolderNumber}) %Prints to console
fullFilePath = strtrim(sprintf('%s/%s.jpg', arguments.filepath, arguments.filename));
image = imread(fullFilePath);
fig1 = figure(1);
set(fig1,'Position', [0, 0, 1000, 400]);
clf
imshow(image)
title('Reference Image')
crop = arguments.defaultCrop; %Initially, at aleast
while 1
fig2 = figure(2);
set(fig2,'Position', [1500, 1000, 200, 150]);
clf
croppedImage = imcrop(image, crop);
imshow(croppedImage)
title(sprintf('Cropped with xmin = %d and ymin = %d', arguments.defaultCrop(1), arguments.defaultCrop(2)))
userAnswer = input('Are you happy with this crop (y/n)? ',"s");
if strcmpi(userAnswer, 'y')
%Save coordinates:
if arguments.saveData
disp('>>>>>> [INFO] Saving crop parameters ...')
save(strtrim(sprintf('%s/%s-cropParams.mat', ...
arguments.filepath, ...
arguments.filename)), ...
'crop')
end
break %Currently, the only way to break out of this while loop.
else
xmin = input('Please input a new xmin: '); % There has to be a faster algorithm here. Too tired to thing. Basically, format to integer.
ymin = input('Please input a new ymin: ');
%Set argument parser. Basically so the user doesn't enter out of
%bounds values.
if xmin < 0 || ymin < 0
disp('[WARNING] Please choose positive integer values for xmin and ymin.')
xmin = input('Please input a new xmin: '); % There has to be a faster algorithm here. Too tired to thing. Basically, format to integer.
ymin = input('Please input ymin: ');
end
if xmin > size(image, 1) || ymin > size(image, 2)
disp('[WARNING] Please choose xmin and ymin based on the total image size.')
xmin = arguments('Please input a new xmin: '); % There has to be a faster algorithm here. Too tired to thing. Basically, format to integer.
ymin = arguments('Please input a new ymin: ');
end
% Updated crop parameters
crop = [xmin ymin WIDTH HEIGHT]; %[xmin ymin width height] of reference image; updated
fprintf('[INFO] New xmin = %i, ymin = %i\n', xmin, ymin)
fig2 = figure(2);
set(fig2,'Position', [1500, 1000, 200, 150]);
clf %clears current figure for update
%pause(0.5)
croppedImage = imcrop(image, crop);
imshow(croppedImage)
title(sprintf('Cropped with xmin = %i and ymin = %i', xmin, ymin))
end
end
%crop
end
%disp('All Done!')