Skip to content

Commit

Permalink
Better support for RGB files
Browse files Browse the repository at this point in the history
- update set_naxispath implementation for RGBImage
- add additional supported mimetypes to pillow- and opencv-based loaders
- RGB video files can be opened (with OpenCv loader) and examined with
  MultiDim plugin or naxis mode (video frames are treated as axis 3)
- small fixes to naxis mode
  • Loading branch information
ejeschke committed Feb 5, 2024
1 parent 6582c0d commit b703e2f
Show file tree
Hide file tree
Showing 6 changed files with 191 additions and 145 deletions.
5 changes: 5 additions & 0 deletions doc/WhatsNew.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ Ver 5.0.0 (unreleased)
- Added mode help; type 'h' in the viewer window when you are in a mode
to display a help tab for that mode (reference viewer only)
- Better support for touchpad gestures in modes
- Better support for RGB files

- Support additional types (ico/icns/tga/bmp)
- RGB video files can be opened (with OpenCv loader) and examined with
MultiDim plugin or naxis mode (video frames is treated as axis 3)

Ver 4.1.0 (2022-06-30)
======================
Expand Down
17 changes: 17 additions & 0 deletions ginga/RGBImage.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,23 @@ def get_buffer(self, format, output=None):
return self.io.get_buffer(self._get_data(), self.get_header(),
format, output=output)

def set_naxispath(self, naxispath):
"""Choose a slice out of multidimensional data.
"""
# Currently, RGBImage only supports regular 3D images (H, W, D)
# But we support a "fake" 4th axis for RGB video files (for this
# you need to use the OpenCv loader)
self.logger.debug(f"naxispath is {naxispath}")
num = naxispath[0]
data = self.io.get_frame(num, metadata=self.metadata)

if data is None or len(data.shape) not in [3]:
raise ImageError(
"naxispath does not lead to a 2D RGB slice: {}".format(naxispath))

self.naxispath = naxispath
self.set_data(data)

def copy(self, astype=None):
other = RGBImage()
self.transfer(other, astype=astype)
Expand Down
4 changes: 2 additions & 2 deletions ginga/modes/naxis.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def __str__(self):
return 'naxis'

def start(self):
pass
self.axis = 3

def stop(self):
self.onscreen_message(None)
Expand Down Expand Up @@ -150,7 +150,7 @@ def ms_naxis(self, viewer, event, data_x, data_y, msg=True):
if event.state in ('down', 'move'):
win_wd, win_ht = viewer.get_window_size()
x_pct = min(max(0.0, x / float(win_wd)), 1.0)
idx = int(x_pct * axis_lim - 1)
idx = int(round(x_pct * (axis_lim - 1)))
naxispath[m] = idx
image.set_naxispath(naxispath)
if msg:
Expand Down
2 changes: 1 addition & 1 deletion ginga/rv/plugins/MultiDim.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def __init__(self, fv, fitsimage):
self.play_idx = 0
self.play_max = 0
self.play_int_sec = 0.1
self.play_min_sec = 1.0 / 30
self.play_min_sec = 0.0
self.play_last_time = 0.0
self.play_fps = 0
self.timer = fv.get_timer()
Expand Down
3 changes: 3 additions & 0 deletions ginga/util/io/io_fits.py
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,10 @@ def close(self):
self.hdu_db = {}
self.extver_db = {}
self.info = None
fits_f = self.fits_f
self.fits_f = None
if fits_f is not None:
fits_f.close()

def find_first_good_hdu(self):

Expand Down
Loading

0 comments on commit b703e2f

Please sign in to comment.