~ubuntu-branches/ubuntu/trusty/guiqwt/trusty

« back to all changes in this revision

Viewing changes to guiqwt/histogram.py

  • Committer: Bazaar Package Importer
  • Author(s): Picca Frédéric-Emmanuel
  • Date: 2011-04-07 22:41:50 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20110407224150-kkhppnq7rp2c8b3c
Tags: 2.1.0-1
* Imported Upstream version 2.1.0
* debian/patches/
  - 0001-features-01_bts614083.patch (delete)
  - 0001-feature-fix-the-documentation-build.patch (new)
* add and install the sift desktop file
* recommends python-dicom (Closes: #621421)
  thanks Junqian Gordon Xu for the report

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
import numpy as np
45
45
from PyQt4.QtCore import Qt
46
46
from PyQt4.QtGui import QHBoxLayout, QVBoxLayout, QToolBar
47
 
from PyQt4.Qwt5 import QwtPlotCurve
48
47
 
49
48
from guidata.dataset.datatypes import DataSet
50
49
from guidata.dataset.dataitems import FloatItem
53
52
from guidata.qthelpers import add_actions, create_action
54
53
 
55
54
# Local imports
 
55
from guiqwt.transitional import QwtPlotCurve
56
56
from guiqwt.config import CONF, _
57
57
from guiqwt.interfaces import (IBasePlotItem, IHistDataSource,
58
58
                               IVoiImageItemType, IPanel)
104
104
        self.old_bins = None
105
105
        self.source = None
106
106
        self.logscale = None
107
 
        self.remove_first_bin = None
108
107
        self.old_logscale = None
109
108
        if curveparam is None:
110
109
            curveparam = CurveParam(_("Curve"), icon='curve.png')
139
138
    def get_logscale(self):
140
139
        """Returns the status of the scale"""
141
140
        return self.logscale
142
 
        
143
 
    def set_remove_first_bin(self, state):
144
 
        self.remove_first_bin = state
145
 
        self.update_histogram()
146
 
        
147
 
    def get_remove_first_bin(self):
148
 
        return self.remove_first_bin
149
141
 
150
142
    def set_bins(self, n_bins):
151
143
        self.bins = n_bins
162
154
            return
163
155
        hist, bin_edges = self.compute_histogram()
164
156
        hist = np.concatenate((hist, [0]))
165
 
        if self.remove_first_bin:
166
 
            hist[0] = 0
167
157
        if self.logscale:
168
158
            hist = np.log(hist+1)
169
159
 
210
200
        
211
201
        self.histparam = HistogramParam(_("Histogram"), icon="histogram.png")
212
202
        self.histparam.logscale = False
213
 
        self.histparam.remove_first_bin = True
214
203
        self.histparam.n_bins = 256
215
204
 
216
205
        self.range = XRangeSelection(0, 1)
223
212
        self.set_active_item(self.range)
224
213
 
225
214
        self.setMinimumHeight(80)
226
 
        self.setAxisMaxMajor(self.yLeft, 5)
227
 
        self.setAxisMaxMinor(self.yLeft, 0)
 
215
        self.setAxisMaxMajor(self.Y_LEFT, 5)
 
216
        self.setAxisMaxMinor(self.Y_LEFT, 0)
228
217
 
229
218
        if parent is None:
230
219
            self.set_axis_title('bottom', 'Levels')
237
226
        self.connect(self, SIG_VOI_CHANGED, plot.notify_colormap_changed)
238
227
        self.connect(plot, SIG_ITEM_SELECTION_CHANGED, self.selection_changed)
239
228
        self.connect(plot, SIG_ACTIVE_ITEM_CHANGED, self.active_item_changed)
240
 
        
241
 
    def standard_tools(self, manager):
242
 
        manager.add_tool(SelectTool)
243
 
        manager.add_tool(BasePlotMenuTool, "item")
244
 
        manager.add_tool(BasePlotMenuTool, "axes")
245
 
        manager.add_tool(BasePlotMenuTool, "grid")
246
 
        manager.add_tool(AntiAliasingTool)
247
 
        manager.get_default_tool().activate()
248
229
 
249
230
    def tracked_items_gen(self):
250
231
        for plot, items in self._tracked_items.items():
298
279
 
299
280
        self.active_item_changed(plot)
300
281
 
 
282
        # Rescaling histogram plot axes for better visibility
 
283
        ymax = None
 
284
        for item in known_items:
 
285
            curve = known_items[item]
 
286
            _x, y = curve.get_data()
 
287
            ymax0 = y.mean()+3*y.std()
 
288
            if ymax is None or ymax0 > ymax:
 
289
                ymax = ymax0
 
290
        ymin, _ymax = self.get_axis_limits("left")
 
291
        if ymax is not None:
 
292
            self.set_axis_limits("left", ymin, ymax)
 
293
            self.replot()
 
294
 
301
295
    def active_item_changed(self, plot):
302
296
        items = plot.get_selected_items(IVoiImageItemType)
303
297
        if not items:
398
392
    """Contrast adjustment tool"""
399
393
    __implements__ = (IPanel,)
400
394
    PANEL_ID = ID_CONTRAST
 
395
    PANEL_TITLE = _("Contrast adjustment tool")
 
396
    PANEL_ICON = "contrast.png"
401
397
 
402
398
    def __init__(self, parent=None):
403
399
        super(ContrastAdjustment, self).__init__(parent)
404
 
        widget_title = _("Contrast adjustment tool")
405
 
        widget_icon = "contrast.png"
406
400
        
407
401
        self.local_manager = None # local manager for the histogram plot
408
402
        self.manager = None # manager for the associated image plot
416
410
        self.max_select_tool = None
417
411
        
418
412
        style = "<span style=\'color: #444444\'><b>%s</b></span>"
419
 
        layout, _label = get_image_layout(widget_icon,
420
 
                                          style % widget_title,
 
413
        layout, _label = get_image_layout(self.PANEL_ICON,
 
414
                                          style % self.PANEL_TITLE,
421
415
                                          alignment=Qt.AlignCenter)
422
416
        layout.setAlignment(Qt.AlignCenter)
423
417
        vlayout = QVBoxLayout()
434
428
        toolbar.setOrientation(Qt.Vertical)
435
429
#        toolbar.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
436
430
        hlayout.addWidget(toolbar)
437
 
        self.histogram.standard_tools(self.local_manager)
438
 
        self.setWindowIcon(get_icon(widget_icon))
439
 
        self.setWindowTitle(widget_title)
440
 
        
441
 
        self.outliers_param = EliminateOutliersParam(widget_title)
 
431
        
 
432
        # Add standard plot-related tools to the local manager
 
433
        lman = self.local_manager
 
434
        lman.add_tool(SelectTool)
 
435
        lman.add_tool(BasePlotMenuTool, "item")
 
436
        lman.add_tool(BasePlotMenuTool, "axes")
 
437
        lman.add_tool(BasePlotMenuTool, "grid")
 
438
        lman.add_tool(AntiAliasingTool)
 
439
        lman.get_default_tool().activate()
 
440
        
 
441
        self.outliers_param = EliminateOutliersParam(self.PANEL_TITLE)
442
442
        
443
443
    def register_panel(self, manager):
444
444
        """Register panel to plot manager"""
449
449
        self.setup_actions()
450
450
        for plot in manager.get_plots():
451
451
            self.histogram.connect_plot(plot)
 
452
                         
 
453
    def configure_panel(self):
 
454
        """Configure panel"""
 
455
        self.min_select_tool = self.manager.add_tool(SelectPointTool,
 
456
                                       title=_("Minimum level"),
 
457
                                       on_active_item=True,mode="create",
 
458
                                       tip=_("Select minimum level on image"),
 
459
                                       toolbar_id="contrast",
 
460
                                       end_callback=self.apply_min_selection)
 
461
        self.max_select_tool = self.manager.add_tool(SelectPointTool,
 
462
                                       title=_("Maximum level"),
 
463
                                       on_active_item=True,mode="create",
 
464
                                       tip=_("Select maximum level on image"),
 
465
                                       toolbar_id="contrast",
 
466
                                       end_callback=self.apply_max_selection)        
452
467
 
453
468
    def get_plot(self):
454
469
        return self.manager.get_active_plot()
470
485
                                           "outliers and scale the image's "
471
486
                                           "display range accordingly") )
472
487
        add_actions(self.toolbar,[fullrange_ac, autorange_ac])
473
 
        self.min_select_tool = self.manager.add_tool(SelectPointTool,
474
 
                                       title=_("Minimum level"),
475
 
                                       on_active_item=True,mode="create",
476
 
                                       tip=_("Select minimum level on image"),
477
 
                                       toolbar_id="contrast",
478
 
                                       end_callback=self.apply_min_selection)
479
 
        self.max_select_tool = self.manager.add_tool(SelectPointTool,
480
 
                                       title=_("Maximum level"),
481
 
                                       on_active_item=True,mode="create",
482
 
                                       tip=_("Select maximum level on image"),
483
 
                                       toolbar_id="contrast",
484
 
                                       end_callback=self.apply_max_selection)        
485
488
    
486
489
    def eliminate_outliers(self):
487
490
        def apply(param):