-
Notifications
You must be signed in to change notification settings - Fork 0
/
image_viewer.m
169 lines (130 loc) · 5.05 KB
/
image_viewer.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
% Sweet Image Viewer
% Author: William Jackson
function [] = image_viewer()
x_pos_lc = 0.87 ;
x_pos_rc = 0.887;
num_width = 0.02;
num_height = 0.017;
y_pos = 0.34;
y_spacing = 0.02;
fig_han.fh = figure('units','Normalized',...
'position',[0,0,0.9,0.9],...
'menubar','none',...
'name','Image Viewer',...
'numbertitle','off',...
'resize','on',... % you can fix it so its scalable
'WindowKeyPressFcn',@key_press);
fig_han.ha = axes('Units','Normalized','Position',[0.033,0.033,0.8,0.8]);
fig_han.inc_text = uicontrol('Style','text','String','Inc Pos',...
'HorizontalAlignment','left',...
'Units','Normalized', 'Position',[x_pos_lc,y_pos,0.04,num_height]);
fig_han.i_inc_str = uicontrol('Style','edit','String','1',...
'Units','Normalized',...
'Position',[x_pos_lc,y_pos-y_spacing,num_width,num_height]);
fig_han.j_inc_str = uicontrol('Style','edit','String','1',...
'Units','Normalized',...
'Position',[x_pos_lc,y_pos-2*y_spacing,num_width,num_height]);
fig_han.k_inc_str = uicontrol('Style','edit','String','1',...
'Units','Normalized',...
'Position',[x_pos_lc,y_pos-3*y_spacing,num_width,num_height]);
fig_han.i_pos_str = uicontrol('Style','edit','String','0',...
'Units','Normalized',...
'Position',[x_pos_rc,y_pos-y_spacing,num_width,num_height]);
fig_han.j_pos_str = uicontrol('Style','edit','String','0',...
'Units','Normalized',...
'Position',[x_pos_rc,y_pos-2*y_spacing,num_width,num_height]);
fig_han.k_pos_str = uicontrol('Style','edit','String','0',...
'Units','Normalized',...
'Position',[x_pos_rc,y_pos-3*y_spacing,num_width,num_height]);
fig_han.base_test = uicontrol('Style','text','String',...
'File Name Pattern','Units','Normalized',...
'Position',[x_pos_lc,y_pos-5*y_spacing,0.1,num_height],...
'HorizontalAlignment','left');
fig_han.base_name = uicontrol('Style','edit','String',...
'image_{}_{}_{}.bmp',...
'Units','Normalized',...
'Position',[x_pos_lc,y_pos-6*y_spacing,0.1,num_height]);
fig_han.load = uicontrol('Style','pushbutton','String','Load',...
'Units','Normalized',...
'Position',[x_pos_lc,y_pos-7*y_spacing,0.04,num_height],...
'Callback', {@load_reset_Callback});
fig_han.image_path = '';
fig_han.enabled = 0;
fig_han.message_shown = 0;
function key_press(~, eventdata)
if fig_han.enabled
draw_it = 0;
ii = str2double(fig_han.i_pos_str.String);
jj = str2double(fig_han.j_pos_str.String);
kk = str2double(fig_han.k_pos_str.String);
curr_inc_i = str2double(fig_han.i_inc_str.String);
curr_inc_j = str2double(fig_han.j_inc_str.String);
curr_inc_k = str2double(fig_han.k_inc_str.String);
switch eventdata.Key
case('leftarrow')
ii = ii - curr_inc_i;
draw_it = 1;
case('rightarrow')
ii = ii + curr_inc_i;
draw_it = 1;
case('uparrow')
jj = jj + curr_inc_j;
draw_it = 1;
case('downarrow')
jj = jj - curr_inc_j;
draw_it = 1;
case('pageup')
kk = kk + curr_inc_k;
draw_it = 1;
case('pagedown')
kk = kk - curr_inc_k;
draw_it = 1;
end
if draw_it
fig_han.i_pos_str.String = num2str(ii);
fig_han.j_pos_str.String = num2str(jj);
fig_han.k_pos_str.String = num2str(kk);
load_and_display()
end
else
if not(fig_han.message_shown)
disp('Click load to enable scrolling with keys')
fig_han.message_shown = 1;
end
end
end
function load_reset_Callback(~, ~)
load_and_display()
end
function get_file_name()
input_string = fig_han.base_name.String;
splits = strsplit(input_string,'{}');
len = length(splits);
if len>1 && len <=4
im_string = "";
else
disp('Invalid image string')
return
end
number_strings = {fig_han.i_pos_str.String,...
fig_han.j_pos_str.String, fig_han.k_pos_str.String};
for ii = 1:len-1
im_string = im_string + splits{ii};
im_string = im_string + number_strings{ii};
end
im_string = im_string + splits{end};
fig_han.image_path = char(im_string);
end
function load_and_display()
fig_han.enabled = 1;
get_file_name();
try
image = imread(fig_han.image_path);
imshow(image);
catch % should rethrow errors that arent file not found...
disp('Image not found')
disp(fig_han.image_path);
return
end
end
end