display image

def display(self, img, title=None, colormap=None, style='image',
                subtitles=None, auto_contrast=False, contrast_level=None, **kws):
        """display image"""
        if title is not None:
            self.SetTitle(title)
        if subtitles is not None:
            self.subtitles = subtitles
        cmode = self.config_mode.lower()[:3]
        img = np.array(img)

        if len(img.shape) == 3:
            ishape = img.shape
            # make sure 3d image is shaped (NY, NX, 3)
            if ishape[2] != 3:
                if ishape[0] == 3:
                    img = img.swapaxes(0, 1).swapaxes(1, 2)
                elif ishape[1] == 3:
                    img = img.swapaxes(1, 2)

            if cmode != 'rgb':
                for comp in self.config_panel.Children:
                    comp.Destroy()
                self.config_mode = 'rgb'
                self.panel.conf.tricolor_mode = 'rgb'
                self.Build_ConfigPanel()
        else:
            if cmode != 'int':
                for comp in self.config_panel.Children:
                    comp.Destroy()
                self.config_mode = 'int'
                self.Build_ConfigPanel()

        if contrast_level is None:
            if auto_contrast:
                cl_str = '1.0'
            else:
                cl_str = self.contrast_panel.choice.GetStringSelection()
        else:
            cl_int = max(np.where(Contrast_NDArray<=contrast_level)[0])
            cl_str = Contrast_List[cl_int]

        if cl_str == 'None':
            contrast_level = 0
        else:
            contrast_level = float(cl_str)

        self.contrast_panel.choice.SetStringSelection(cl_str)
        self.panel.conf.contrast_level = contrast_level

        self.panel.display(img, style=style, contrast_level=contrast_level,
                           **kws)

        self.set_contrast_levels(contrast_level=contrast_level)

        self.panel.conf.title = title
        if colormap is not None and self.config_mode == 'int':
            self.cmap_panels[0].set_colormap(name=colormap)

        if subtitles is not None:
            if isinstance(subtitles, dict):
                self.set_subtitles(**subtitles)
            elif self.config_mode == 'int':
                self.set_subtitles(red=subtitles)

        self.panel.conf.style = 'image'
        self.contrast_panel.Enable()
        self.interp_panel.Enable()
        if style == 'contour':
            self.panel.conf.style = 'contour'
            self.contrast_panel.Disable()
            self.interp_panel.Disable()

        self.config_panel.Refresh()
        self.SendSizeEvent()
        wx.CallAfter(self.EnableMenus)