;iIdZddlZddlZddlmZddlmZddlmZddl m Z m Z m Z dd l m Z dd lmZdd lmZdd lmZdd lmZddlmZdgZGddeZdS)zz GraphicsWidget displaying an image histogram along with gradient editor. Can be used to adjust the appearance of images. N)debug) functions)Point)QtCoreQtGui QtWidgets)AxisItem)GradientEditorItem)GraphicsWidget)LinearRegionItem) PlotCurveItem)ViewBoxHistogramLUTItemceZdZdZejeZejeZejeZ d dZ d!d Z d Z d"d Z dZdZdZdZdZdZdZd#dZdZdZd$dZdZd#dZdZdZdZdZdS)%ra* :class:`~pyqtgraph.GraphicsWidget` with controls for adjusting the display of an :class:`~pyqtgraph.ImageItem`. Includes: - Image histogram - Movable region over the histogram to select black/white levels - Gradient editor to define color lookup table for single-channel images Parameters ---------- image : pyqtgraph.ImageItem, optional If provided, control will be automatically linked to the image and changes to the control will be reflected in the image's appearance. This may also be set via :meth:`setImageItem`. fillHistogram : bool, optional By default, the histogram is rendered with a fill. Performance may be improved by disabling the fill. Additional control over the fill is provided by :meth:`fillHistogram`. levelMode : str, optional 'mono' (default) One histogram with a :class:`~pyqtgraph.LinearRegionItem` is displayed to control the black/white levels of the image. This option may be used for color images, in which case the histogram and levels correspond to all channels of the image. 'rgba' A histogram and level control pair is provided for each image channel. The alpha channel histogram and level control are only shown if the image contains an alpha channel. gradientPosition : str, optional Position of the gradient editor relative to the histogram. Must be one of {'right', 'left', 'top', 'bottom'}. 'right' and 'left' options should be used with a 'vertical' orientation; 'top' and 'bottom' options are for 'horizontal' orientation. orientation : str, optional The orientation of the axis along which the histogram is displayed. Either 'vertical' (default) or 'horizontal'. Attributes ---------- sigLookupTableChanged : QtCore.Signal Emits the HistogramLUTItem itself when the gradient changes sigLevelsChanged : QtCore.Signal Emits the HistogramLUTItem itself while the movable region is changing sigLevelChangeFinished : QtCore.Signal Emits the HistogramLUTItem itself when the movable region is finished changing See Also -------- :class:`~pyqtgraph.ImageItem` HistogramLUTItem is most useful when paired with an ImageItem. :class:`~pyqtgraph.ImageView` Widget containing a paired ImageItem and HistogramLUTItem. :class:`~pyqtgraph.HistogramLUTWidget` QWidget containing a HistogramLUTItem for widget-based layouts. NTmonorightverticalc h tj|d|_d|_||_||_||_|dkr |dvrd|_n|dkr |dvrd|_tj|_ | |j |j dddd|j d t| |_|jdkrQ|jd |jd |jd dnP|jd |jd |jdd t)|j|_|jd|jdkrdnd}t/d dg|dt/d dg|ddt1jddt/d dg|ddt1jddt/d dg|ddt1jddt/d dg|ddt1jddg|_|jd |_|jD]}|d |j||jd d!d"|jdd#d"|j !|j"|j#!|j$dd$dd%d&|j}tK||jd'|(|_&|jd)vrd*nd+} |jdkrv|j |j&d | d |j |jd | d|j |jd | d,nu|j |j&| d d |j |j| dd |j |j| d,d |j'|jj(j)|j'|jj(j)|jj*!|j+|jj,!|j-t\j/j0j1} ted-.ted/| 0ted1| 0ted2| 0ted-| 0g|_3|j3d |_4|j3D]<} |jdkr| 5d3|j| =|6||7|8||9|dSdS)4NcdSNr\C:\PYTHON\MyICR_Workspace\venv\Lib\site-packages\pyqtgraph/graphicsItems/HistogramLUTItem.pyz+HistogramLUTItem.__init__..\srr>leftrr horizontal>topbottomr r r)parent-FT)xy) orientationgreyblock)swapModer)2r,r,)UUUUUU?)r)penbrushspang)r,r+r,r,)r.UUUUUU?b)r,r,r+P)r3?wr+r+r+r,iz<|g?z|>rr)rrrr i)linkView maxTickLengthr!>rr )rr r)rr rr)r;r;d)r/)r+rrr<)r/compositionMode)rr+rr<)rrr+r<Z):r __init__lut imageItem levelModer&gradientPositionr QGraphicsGridLayoutlayout setLayoutsetContentsMargins setSpacingrvbsetMaximumWidthsetMinimumWidthsetMouseEnabledsetMaximumHeightsetMinimumHeightr gradient loadPresetrfnmkBrushregionsregion setZValueaddItemlines addMarkersigRegionChangedconnectregionChangingsigRegionChangeFinished regionChangedr axissetFlagGraphicsItemFlagItemStacksBehindParentsigGradientChangedgradientChangedsigRangeChangedviewRangeChangedrQPainterCompositionModeCompositionMode_Plusrplotsplot setRotation fillHistogram _showRegionsautoHistogramRange setImageItem) selfimagerlrBrCr&regionOrientationrTaxavgcomprjs rr?zHistogramLUTItem.__init__Xs&%%%%"& 0 * $ $)9AR)R)R$+D ! ! L ( (-=EV-V-V$,D !355  t{### &&q!Q222 q!!!&&&  z ) ) G # #C ( ( ( G # #B ' ' ' G # #et # 4 4 4 4 G $ $S ) ) ) G $ $R ( ( ( G # #de # 4 4 4*t7LMMM    (((-1,< ,J,JLLPZ aV%6 I I I aV%6c#%:.?#@#@z S S S aV%6c#%:.?#@#@| U U U aV%6c#%:.?#@#@z S S S aV%6c#%:.A#B#B U U U   l1o l G GF   T " " " GOOF # # # LO % %dC 0 0 0 LO % %dC 0 0 0  # + +D,? @ @ @  * 2 243E F F F F00040EGR$'TRRR  04GGGiiY  z ) ) K   1c!f 5 5 5 K  CF 3 3 3 K   q#a& 9 9 9 9 K   3q61 5 5 5 K  Q 3 3 3 K   s1vq 9 9 9 dm<STTT  6MNNN (001EFFF ''(=>>>~-B 2 3 3 3 . E E E . E E E . E E E 2D I I I   JqM J " "D:--  $$$ GOOD ! ! ! ! =)))  !!!     e $ $ $ $ $  rr-r<r<r;c|ddddg}t||jD]G\}}|r+||||2|dHdS)a8Control fill of the histogram curve(s). Parameters ---------- fill : bool, optional Set whether or not the histogram should be filled. level : float, optional Set the fill level. See :meth:`PlotCurveItem.setFillLevel `. Only used if ``fill`` is True. color : color_like, optional Color to use for the fill when the histogram ``levelMode == "mono"``. See :meth:`PlotCurveItem.setBrush `. )r+rrr,)rr+rr,)rrr+r,r8N)zipri setFillLevelsetBrush)rpfilllevelcolorcolorsrjs rrlzHistogramLUTItem.fillHistograms/?L_`vtz22 ( (KE4 (!!%((( e$$$$!!$''''  ( (rcP|jdks|jsdS|jjdj}|\}}|j}|j |j j }|j dkr|j|t||tddz}|j|t||tddz } |jdkr*|} |} n|} |} n|j|t||tddz }|j|t||tddz} |jdkr)|} |} n(|} |} |t0jjjt9jdd |fD]8}||||| || | |j dkru||||||||||||:dS) Nrrrrr )rrrr<)width) rBrT isVisiblerWr/ getLevelsrIviewRectcenterrOmapRectToParentgradRectrectr&mapFromViewToItemrr$rC bottomLefttopLeft bottomRighttopRightr% setRenderHintrrf RenderHint AntialiasingrQmkPensetPendrawLine) rppargsr/mnmxvbcrp1mnp1mxp2mnp2mxs rpaintzHistogramLUTItem.paintsq >V # #4;+@+@+B+B # Fk"&!!Bg  ''))=001G1L1L1N1NOO  z ) )7,,T5"3E3EFFqRSTD7,,T5"3E3EFFqRSTD$//**,,''))++--((**7,,T5SUUWW3E3EFFqRSTD7,,T5SUUWW3E3EFFqRSTD$00''))((****,,++-- 1>???H^1555s; H HC HHSMMM JJtT " " " JJtT " " ":-- 8++--x/@/@/B/BCCC 8..00(2F2F2H2HIIII 8++--x/B/B/D/DEEE 8,,..0D0D0F0FGGGG H Hr皙?c$|jdkrC|j|jjd|j|||dS|j|jjd|j|||dS)zbSet the X/Y range on the histogram plot, depending on the orientation. This disables auto-scaling.rFN)r&rIenableAutoRangeYAxis setYRangeXAxis setXRange)rprrpaddings rsetHistogramRangez"HistogramLUTItem.setHistogramRanges  z ) ) G # #DGM5 9 9 9 G  b"g . . . . . G # #DGM5 9 9 9 G  b"g . . . . .rc|jdkr|jdS|jdS)z$Returns range on the histogram plot.rr r)r&rI viewRangerps rgetHistogramRangez"HistogramLUTItem.getHistogramRange sB  z ) )7$$&&q) )7$$&&q) )rcN|j|jjdS)z*Enable auto-scaling on the histogram plot.N)rIrXYAxesrs rrnz#HistogramLUTItem.autoHistogramRanges" /////rcN|j|jjdS)z+Disable auto-scaling on the histogram plot.N)rIdisableAutoRangerrs rdisableAutoHistogramRangez*HistogramLUTItem.disableAutoHistogramRanges"   00000rctj||_t|dr|j|j|||ddS)zoSet an ImageItem to have its levels and LUT automatically controlled by this HistogramLUTItem. sigImageChangedT) autoLevelN) weakrefrefrAhasattrrrZ imageChanged_setImageLookupTabler])rpimgs rrozHistogramLUTItem.setImageItems!S)) 3) * * ;   ' '(9 : : : !!###  D)))))rc.|dSr)updaters rrez!HistogramLUTItem.viewRangeChanged#s rc||d|_|j|dSr)rArr@sigLookupTableChangedemitrs rrcz HistogramLUTItem.gradientChanged&sH >>   '  % % ' ' ' "''-----rc|jr)|ddS||jdSr)rOisLookupTrivialrAsetLookupTablegetLookupTablers rrz%HistogramLUTItem._setImageLookupTable-sd = ( ( * * A NN   + +D 1 1 1 1 1 NN   + +D,? @ @ @ @ @rc|jdkrdS||jtjkrd}nd}|j!|j|||_|jS)z`Return a lookup table from the color gradient defined by this HistogramLUTItem. rNi)alpha)rBdtypenpuint8r@rOr)rprnrs rrzHistogramLUTItem.getLookupTable3sa >V # #4 9yBH$$ 8 }33AU3CCDHxrc|9|||j|dSr)rA setLevelsrsigLevelChangeFinishedrrs rr]zHistogramLUTItem.regionChangedBsW >>   ' NN   & &t~~'7'7 8 8 8 #((.....rc|9||||j|dSr)rArrrsigLevelsChangedrrs rr[zHistogramLUTItem.regionChangingGsd >>   ' NN   & &t~~'7'7 8 8 8  ""4(((((rFc|dS|jdkr=|jddD]}|d|jddt j}|}|d|ddS|jj||d|rE|dd}|dd}|j ||g|d dS| \}}|j ||gdS|jdd|d }|ddStdd D]} t|| kr|| dz }|j| d|j| j||r>|dd}|dd}|j|  ||g|j| d|dS) Nrr FrTz get histogramzset plotz set region) perChannelr)rArBri setVisiblerProfiler getHistogramrjsetDatarT setRegionrrangelenrSrm) rpr autoRangepltprofilerhrrchis rrzHistogramLUTItem.imageChangedMs >>   # F >V # #z!""~ & &u%%%% JqM $ $T * * *~''H  --//A H_ % % %t| DI q ! ! HZ  0qT!WqT"X %%r2h///&&&&&))3355B %%r2h///// JqM $ $U + + +!!..$.??B!u}1a[[ 4 4r77a<<1Q3AJqM,,T222)DJqM)1-- <qT!WqT"X Q112r(;;;JqM,,U3333        rc|jdkr|jS|}|d}d|jd|dzDS)zsReturn the min and max levels. For rgba mode, this returns a list of the levels for each channel. rNrc6g|]}|Sr) getRegion).0r*s r z.HistogramLUTItem.getLevels..s AAAaAKKMMAAArr )rBrTrrAchannelsrS)rpnchs rrzHistogramLUTItem.getLevelszsm >V # #;((** *..""++--C{AA4<#a%+@AAA Arc8d||hvr| d|dvrtd|jdkr+| |d\}}|j||fdS|d||fgz}t ||jddD]\}}||dS)a4Set the min/max (bright and dark) levels. Parameters ---------- min : float, optional Minimum level. max : float, optional Maximum level. rgba : list, optional Sequence of (min, max) pairs for each channel for 'rgba' mode. NrzMust specify min and max levelsrr ) ValueErrorrBrTrrxrS)rpminmaxrgbalevelsrTs rrzHistogramLUTItem.setLevelss C:  4<447??>?? ? >V # #{7S K ! !3* - - - - -|3*~"%dDL,<"="= ) )  (((( ) )rc>|dvrtd|||jkrdS|}||_||dkr3t j|d}|j|n|gdz}|||9||| | dS) zsSet the method of controlling the image levels offered to the user. Options are 'mono' or 'rgba'. >rrz0Level mode must be one of {'mono', 'rgba'}, got Nrr)r^r)r) rrBrrmrarraymeanrrArr)rpmode oldLevelsrs r setLevelModezHistogramLUTItem.setLevelModes ' ' 'XRVXXYY Y 4> ! ! FNN$$   6>>Xi((--1-55F DNF # # #[1_F NNN ' ' ' >>   ' NN   & &t~~'7'7 8 8 8  rctt|jD]"}|j|d#|jdkrd}|*|}|d}d|z }td|dzD]L}|j|d|j||dz |z||zM|j dS|jdkr;|jd d|j dStd |j) NFrrrr6r TrrzUnknown level mode ) rrrSrrBrArsetSpanrOhideshowr)rprrxdifs rrmzHistogramLUTItem._showRegionssfs4<(()) . .A LO & &u - - - - >V # #C~~+nn&&//11;C9D1c!e__ @ @ Q**4000 Q''1 a$h???? M   ^v % % LO & &t , , , M   C4>CCDD Drcj|j||jdS)N)rOrr)rO saveStaterrBrs rrzHistogramLUTItem.saveStates4 //11nn&&N   rcd|vr||d|j|d|j|ddS)NrrOr)rrO restoreStater)rpstates rrzHistogramLUTItem.restoreStatesW U??   eFm , , , ""5#4555h((((r)NTrrr)Tr-rv)r)NNN)FF)__name__ __module__ __qualname____doc__rSignalobjectrrrr?rlrrrrnrrorercrrr]r[rrrrrmrrrrrrrs88t*FM&11$v}V,,*V]622AG7Ab%b%b%b%H((((,,H,H,H\////***000111 * * *...AAA    /// ))) + + + + Z B B B))))2>EEE,   )))))r)rrnumpyrrrrQrQtrrr r r r rrr__all__rrrrrs, ))))))))))222222******......((((((  G)G)G)G)G)~G)G)G)G)G)r