Skip to content

Commit

Permalink
daatset scroller - tested and working - version update included
Browse files Browse the repository at this point in the history
  • Loading branch information
mattclifford1 committed Aug 5, 2024
1 parent e70414e commit c97d429
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 13 deletions.
24 changes: 17 additions & 7 deletions IQM_Vis/UI/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,14 @@ def redo_plots(self, calc_range=False):
change image in dataset
'''
def change_preview_images(self, ival):
# have roll around scrolling
if self.preview_num + ival < 0:
return
self.preview_num = self.max_data_ind - self.num_images_scroll_show + 1
elif self.preview_num + ival + self.num_images_scroll_show > self.max_data_ind + 1:
return
self.preview_num = 0
else:
self.preview_num += ival
self.set_preview_images(self.preview_num)
self.set_preview_images(self.preview_num)

def set_preview_images(self, preview_num):
for data_store in self.data_stores:
Expand All @@ -94,15 +95,25 @@ def set_preview_images(self, preview_num):
im_preview_data = data_store.get_reference_image_by_index(
im_preview_ind)
self.widget_im_num_hash[i] = im_preview_ind
# set image preview size
scale = self.num_images_scroll_show - 1
if isinstance(self.image_display_size, list) or isinstance(self.image_display_size, tuple):
preview_size = (self.image_display_size[0]//self.num_images_scroll_show, self.image_display_size[1]//self.num_images_scroll_show)
preview_size = (self.image_display_size[0]//scale, self.image_display_size[1]//scale)
else:
preview_size = self.image_display_size//scale
# determine if we have the current display image
if self.data_num == im_preview_ind:
border = True
else:
preview_size = self.image_display_size//self.num_images_scroll_show
border = False
gui_utils.change_im(self.widget_controls['images'][i], im_preview_data,
resize=preview_size, rgb_brightness=self.rgb_brightness, display_brightness=self.display_brightness)
resize=preview_size, rgb_brightness=self.rgb_brightness, display_brightness=self.display_brightness, border=border)
self.widget_controls['label']['data_num'].setText(
f'({preview_num+1}-{im_preview_ind+1}/{self.max_data_ind+1})')

def change_data_click_im(self, widget_ind, *args): # args sent are position of mouse click on the image widget
self.change_to_data_num(self.widget_im_num_hash[widget_ind])
self.set_preview_images(self.preview_num) # refresh boarder on image

def change_to_data_num(self, ind): # change to an exact ind in the data list
# check the num is within the data limits
Expand Down Expand Up @@ -152,7 +163,6 @@ def change_data(self, ival, _redo_plots=True):
# otherwise from the datastore scores
elif hasattr(data_store, 'human_scores'):
self.human_experiment_scores[i] = data_store.human_scores
self.widget_controls['label']['data_num'].setText(f'({self.data_num+1}/{self.max_data_ind+1})')

def load_new_single_image(self):
''' change the image we are using '''
Expand Down
2 changes: 1 addition & 1 deletion IQM_Vis/UI/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def __init__(self,
restrict_options=None,
num_steps_range=11,
num_step_experiment=6,
num_images_scroll_show=5,
num_images_scroll_show=7,
test=False
):
super().__init__()
Expand Down
11 changes: 8 additions & 3 deletions IQM_Vis/data_handlers/data_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def _load_image_data(self, i):
self.image_post_processing_hash = None
self.current_file = self.image_list[i]
image_name_ref = get_image_name(self.current_file)
image_data_ref = self.image_loader(self.current_file)
image_data_ref = self._cached_image_loader(self.current_file)
self.reference_unprocessed = image_data_ref
if self.image_pre_processing is not None:
image_data_ref = self.image_pre_processing(image_data_ref)
Expand All @@ -133,7 +133,8 @@ def _load_image_data(self, i):
self.image_to_transform = self.image_storer(image_name_ref, image_data_ref)
else:
image_name_trans = get_image_name(self.image_list_to_transform[i])
image_data_trans = self.image_loader(self.image_list_to_transform[i])
image_data_trans = self._cached_image_loader(
self.image_list_to_transform[i])
if self.image_pre_processing is not None:
image_data_trans = self.image_pre_processing(image_data_trans)
self.image_reference = self.image_storer(image_name_trans, image_data_trans)
Expand All @@ -151,11 +152,15 @@ def __len__(self):
def __getitem__(self, i):
self._load_image_data(i)

@cache
def _cached_image_loader(self, file_name):
return self.image_loader(file_name)

def get_reference_image_by_index(self, index):
if index >= len(self.image_list):
raise IndexError('Index out of range of the length of the image list')
file_name = self.image_list[index]
image_data = self.image_loader(file_name)
image_data = self._cached_image_loader(file_name)
return image_data

def get_reference_image_name(self):
Expand Down
8 changes: 7 additions & 1 deletion IQM_Vis/utils/gui_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
# return img_as_ubyte(down_im)


def change_im(widget, im, resize=False, rgb_brightness=250, display_brightness=250):
def change_im(widget, im, resize=False, rgb_brightness=250, display_brightness=250, border=False):
'''
given a numpy image, changes the given widget Frame
'''
Expand All @@ -46,6 +46,12 @@ def change_im(widget, im, resize=False, rgb_brightness=250, display_brightness=2
im = resize_to_longest_side(im, resize)
im = img_as_ubyte(im)
im = calibrate_brightness(im, rgb_brightness, display_brightness)
if border == True:
# add a black border to the image
im = np.pad(im, ((5, 5), (5, 5), (0, 0)), 'constant', constant_values=0)
if resize:
im = resize_to_longest_side(im, resize)
im = img_as_ubyte(im)
qimage = QImage(im,
im.shape[1],
im.shape[0],
Expand Down
2 changes: 1 addition & 1 deletion IQM_Vis/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
# License: BSD 3-Clause License

# Changing the version number will action GitHub to push to PyPi the new version
__version__ = '0.2.5.89'
__version__ = '0.2.5.90'

0 comments on commit c97d429

Please sign in to comment.