;i̇ddlZddlmZddlZddlmZddlmZddlmZddlm Z ddlm Z dd l m Z dd l m Z mZmZdd lmZd d lmZe jjZdgZGddeZdS)N)Callable)colormap)debug) functions)functions_qimage)getConfigOption)Point)QtCoreQtGui QtWidgets)getCupy)GraphicsObject ImageItemceZdZdZejZejeZd:dZ dZ dZ dZ dZ dZd Zd;d Zd Zd ZdZd;dZedZd;dZd;dZdZdZdZddZ"dZ#d Z$d!Z%d"Z& d?d'Z'd(Z(d)Z)d*Z*d+Z+d,Z,d-Z-d.Z.d/Z/d0Z0d1Z1d2Z2d3Z3d:d4Z4d@d7Z5d8Z6d9Z7dS)ArzG **Bases:** :class:`GraphicsObject ` Nc tj|d|_d|_d|_d|_d|_d|_d|_d|_ d|_ d|_ d|_ d|_ d|_d|_d|_d|_d|_t'd|_dx|_|_||jd|_d|_d|_||j|fi|dS|jdi|dS)a See :func:`~pyqtgraph.ImageItem.setOpts` for further keyword arguments and and :func:`~pyqtgraph.ImageItem.setImage` for information on supported formats. Parameters ---------- image: np.ndarray, optional Image data NFrrTimageAxisOrder)r__init__menuimageqimage paintModelevelslutautoDownsample _colorMap_lastDownsample_processingBuffer_displayBuffer_renderRequired _unrenderable_xp_defferedLevels _imageHasNans_imageNanLocationsr axisOrder_dataTransform_inverseDataTransform_update_data_transforms drawKernelborder removablesetImagesetOpts)selfrkargss UC:\PYTHON\MyICR_Workspace\venv\Lib\site-packages\pyqtgraph/graphicsItems/ImageItem.pyrzImageItem.__init__s$ %%%    #%!%"#"#!"&()9::;??d8 $$dn666    DM% ) )5 ) ) ) ) ) DL ! !5 ! ! ! ! !c<||_|dS)as Change the composition mode of the item. This is useful when overlaying multiple items. Parameters ---------- mode : ``QtGui.QPainter.CompositionMode`` Composition of the item, often used when overlaying items. Common options include: ``QPainter.CompositionMode.CompositionMode_SourceOver`` (Default) Image replaces the background if it is opaque. Otherwise, it uses the alpha channel to blend the image with the background. ``QPainter.CompositionMode.CompositionMode_Overlay`` Image color is mixed with the background color to reflect the lightness or darkness of the background ``QPainter.CompositionMode.CompositionMode_Plus`` Both the alpha and color of the image and background pixels are added together. ``QPainter.CompositionMode.CompositionMode_Plus`` The output is the image color multiplied by the background. See ``QPainter::CompositionMode`` in the Qt Documentation for more options and details N)rupdate)r2modes r4setCompositionModezImageItem.setCompositionModeHs8 r5c`tj||_|dS)z Defines the border drawn around the image. Accepts all arguments supported by :func:`~pyqtgraph.mkPen`. N)fnmkPenr.r7r2bs r4 setBorderzImageItem.setBordergs$ hqkk  r5cV|jdS|jdkrdnd}|jj|S)N col-majorrrrr)shaper2axiss r4widthzImageItem.widtho4 : 4Nk11qqqz%%r5cV|jdS|jdkrdnd}|jj|S)NrArrrBrDs r4heightzImageItem.heighturGr5c\|jdS|jjdkr|jjdndS)Nrr)rndimrCr2s r4channelszImageItem.channels{s2 : 4&*jo&:&:tz""Ar5c |jtjddddStjddt|t|S)N)rr QRectFfloatrFrIrMs r4 boundingRectzImageItem.boundingRectsV : =RR00 0}RU4::<<%8%8% :N:NOOOr5Tc|j||_||_dS||j|}||_|r|dSdS)a Sets image scaling levels. See :func:`makeARGB ` for more details on how levels are applied. Parameters ---------- levels: array_like - ``[blackLevel, whiteLevel]`` sets black and white levels for monochrome data and can be used with a lookup table. - ``[[minR, maxR], [minG, maxG], [minB, maxB]]`` sets individual scaling for RGB values. Not compatible with lookup tables. update: bool, optional Controls if image immediately updates to reflect the new levels. N)r%rr&asarray updateImage)r2rr7s r4 setLevelszImageItem.setLevelssl 8  DK#)D F  X%%f--F            r5c|jS)z Returns the list representing the current level settings. See :func:`~setLevels`. When ``autoLevels`` is active, the format is ``[blackLevel, whiteLevel]``. )rrMs r4 getLevelszImageItem.getLevelss {r5c"t|tjr||_n>t|trtj||_nt d||jddS)a Sets a color map for false color display of a monochrome image. Parameters ---------- colorMap : :class:`~pyqtgraph.ColorMap` or `str` A string argument will be passed to :func:`colormap.get() ` z.'colorMap' argument must be ColorMap or string)nPtsN) isinstancerColorMaprstrget TypeErrorsetLookupTablegetLookupTable)r2colorMaps r4 setColorMapzImageItem.setColorMaps h 1 2 2 N%DNN # & & N%\(33DNNLMM M T^:::DDFFFFFr5c|jS)z^ Returns the assigned :class:`pyqtgraph.ColorMap`, or `None` if not available )rrMs r4 getColorMapzImageItem.getColorMaps ~r5c||jurA|j|||j}||_|r|dSdSdS)a6 Sets lookup table ``lut`` to use for false color display of a monochrome image. See :func:`makeARGB ` for more information on how this is used. Optionally, `lut` can be a callable that accepts the current image as an argument and returns the lookup table to use. Ordinarily, this table is supplied by a :class:`~pyqtgraph.HistogramLUTItem`, :class:`~pyqtgraph.GradientEditorItem` or :class:`~pyqtgraph.ColorBarItem`. Setting ``update = False`` avoids an immediate image update. N)rr%_ensure_proper_substraterV)r2rr7s r4rbzImageItem.setLookupTablesi dh  x#33CBBDH #  """""   # #r5cv|*t|tst||jr|St}||kr+t||js||}nK|t kr@|*t||jr|}nt j|}|SN)r]rndarrayrrUnumpyr`)data substratecupys r4riz"ImageItem._ensure_proper_substrates <:dH55<D)J[9\9\<Kyy   Zdl%C%C <<%%DD %  JtT\$B$Bxxzz}T** r5cJ||_d|_|dS)a Controls automatic downsampling for this ImageItem. If `active` is `True`, the image is automatically downsampled to match the screen resolution. This improves performance for large images and reduces aliasing. If `autoDownsample` is not specified, then ImageItem will choose whether to downsample the image based on its size. `False` disables automatic downsampling. TN)rr#r7)r2actives r4setAutoDownsamplezImageItem.setAutoDownsamples%%# r5c d|vr<|d}|dvrtd||_||jd|vr||dd|vr||d|d|vr||d|d|vr||dd |vr||d d |vr||d d |vr|d |_ d |_ d |vr| |d d|vr| |d|r| d Sd S)a Sets display and processing options for this ImageItem. :func:`~pyqtgraph.ImageItem.__init__` and :func:`~pyqtgraph.ImageItem.setImage` support all keyword arguments listed here. Parameters ---------- autoDownsample: bool See :func:`~pyqtgraph.ImageItem.setAutoDownsample`. axisOrder: str | `'col-major'`: The shape of the array represents (width, height) of the image. This is the default. | `'row-major'`: The shape of the array represents (height, width). border: bool Sets a pen to draw to draw an image border. See :func:`~pyqtgraph.ImageItem.setBorder`. compositionMode: See :func:`~pyqtgraph.ImageItem.setCompositionMode` colorMap: :class:`~pyqtgraph.ColorMap` or `str` Sets a color map. A string will be passed to :func:`colormap.get() ` lut: array_like Sets a color lookup table to use when displaying the image. See :func:`~pyqtgraph.ImageItem.setLookupTable`. levels: array_like Shape of (min, max). Sets minimum and maximum values to use when rescaling the image data. By default, these will be set to the estimated minimum and maximum values in the image. If the image array has dtype uint8, no rescaling is necessary. See :func:`~pyqtgraph.ImageItem.setLevels`. opacity: float Overall opacity for an RGB image. Between 0.0-1.0. rect: :class:`QRectF`, :class:`QRect` or array_like Displays the current image within the specified rectangle in plot coordinates. If ``array_like``, should be of the of ``floats (`x`,`y`,`w`,`h`)`` . See :func:`~pyqtgraph.ImageItem.setRect`. update : bool, optional Controls if image immediately updates to reflect the new options. r)) row-majorrAz3axisOrder must be either 'row-major' or 'col-major'rdr)r7ropacitycompositionModer.r/Nrrect) ValueErrorr)r,rerbrW setOpacityr9r?r/rrssetRectr7)r2r7r3vals r4r1zImageItem.setOptssH %   $C444 !VWWW DN  ( ( 8 8 8      U:. / / / E>>   e V  < < < u   NN5?6N : : :    OOE), - - -  % %  # #E*;$< = = = u   NN5? + + + %  ";/DNDI u $ $  " "5)9#: ; ; ; U?? LLv ' ' '   KKMMMMM  r5ct|dkr|dSt|dtjtjfr |d}n,t |ddr|d}tj|}tj}| | | | | | z ||z ||dS)a setRect(rect) or setRect(x,y,w,h) Sets translation and scaling of this ImageItem to display the current image within the rectangle given as ``rect`` (:class:`QtCore.QRect` or :class:`QtCore.QRectF`), or described by parameters `x, y, w, h`, defining starting position, width and height. This method cannot be used before an image is assigned. See the :ref:`examples ` for how to manually set transformations. rN__len__)lenresetTransformr]r rQQRecthasattrr QTransform translatelefttopscalerFrI setTransform)r2argsrxtrs r4r{zImageItem.setRect-s  t99>>    ! ! ! F d1g v|< = = *7DDtAwy)) Aw=4)D     TYY[[$((**---  ,dkkmmdkkmm.KLLL "r5cd|_|||dS)z, Clears the assigned image. N)rprepareGeometryChangeinformViewBoundsChangedr7rMs r4clearzImageItem.clearFs@  ""$$$ $$&&& r5c(tj|dddztj|_|jt kr7|j|dddz|jj|_n |j|_d|_dS)Nr)dtype)rmemptyubyter"r%rr!r)r2rCs r4_buildQImageBufferzImageItem._buildQImageBufferOs}#k%)d*:%+NNN 8wyy %)X^^E"1"I4DDHN^%[%[D " "%)%8D " r5c htj}d}| |jdSn|j}t }|r||nt |_d}||jk}|rd|_|p|jdup|j|jjk} | }||_d|_ d|_ |jjddks|jjddkr d|vrd|d<| r(| | || d|vrd}nd}|rt|d d } || \} } | | ks4|j| s|j| rd} d } | | g|d<||jdd di||d|_|||r|j|j%|j} d|_|| dSdS)a Updates the image displayed by this ImageItem. For more information on how the image is processed before displaying, see :func:`~pyqtgraph.makeARGB`. For backward compatibility, image data is assumed to be in column-major order (column, row) by default. However, most data is stored in row-major order (row, column). It can either be transposed before assignment:: imageitem.setImage(imagedata.T) or the interpretation of the data can be changed locally through the ``axisOrder`` keyword or by changing the `imageAxisOrder` :ref:`global configuration option ` All keywords supported by :func:`~pyqtgraph.ImageItem.setOpts` are also allowed here. Parameters ---------- image: np.ndarray, optional Image data given as NumPy array with an integer or floating point dtype of any bit depth. A 2-dimensional array describes single-valued (monochromatic) data. A 3-dimensional array is used to give individual color components. The third dimension must be of length 3 (RGB) or 4 (RGBA). rect: QRectF or QRect or array_like, optional If given, sets translation and scaling to display the image within the specified rectangle. If ``array_like`` should be the form of floats ``[x, y, w, h]`` See :func:`~pyqtgraph.ImageItem.setRect` autoLevels: bool, optional If `True`, ImageItem will automatically select levels based on the maximum and minimum values encountered in the data. For performance reasons, this search subsamples the images and may miss individual bright or or dark points in the data set. If `False`, the search will be omitted. The default is `False` if a ``levels`` keyword argument is given, and `True` otherwise. levelSamples: int, default 65536 When determining minimum and maximum values, ImageItem only inspects a subset of pixels no larger than this number. Setting this larger than the total number of pixels considers all values. FNTrirrr levelSamplesi) targetSizer7r)rProfilerrr%rget_array_modulermr!rCviewr'r(rrpop quickMinMaxisnanr1r#r7sigImageChangedemitr&rW)r2r autoLevelsr3profile gotNewDataold_xpcpprocessingSubstrateChanged shapeChanged level_samplesmnmxrs r4r0zImageItem.setImageWsN."" =z!"XFB57Br**5111UDHJ)/48); &) .)-&6o$*:LoPUP[_c_i_oPoLJJLLEDJ!%D &*D #z"W,, 0@0Cg0M0M#500.2E*+ /**,,,,,...  5  " !  &!IIne<>"--x1C1Cx!"gE(O  ++E+U+++ #   (  % % ' ' '   +)F#'D NNF $ $ $ $ $ , +r5rAcTtj|_tj|_|jdkrl|jdd|jd|jdd|jddSdS)zF Sets up the transforms needed to map between input array and display ruriN)r rr*r+r)rrotate)r2r)s r4r,z!ImageItem._update_data_transformss#.00%*%5%7%7" >[ ( (   % %a , , ,   & &s + + +  & , ,Q 3 3 3  & - -c 2 2 2 2 2 ) (r5c|jS)a Returns the transform that maps from this image's input array to its local coordinate system. This transform corrects for the transposition that occurs when image data is interpreted in row-major order. :meta private: )r*rMs r4 dataTransformzImageItem.dataTransforms ""r5c|jS)zReturn the transform that maps from this image's local coordinate system to its input array. See dataTransform() for more information. :meta private: )r+rMs r4inverseDataTransformzImageItem.inverseDataTransforms ))r5c6|j|Srk)r+mapr2objs r4 mapToDatazImageItem.mapToDatas)--c222r5c6|j|Srk)r*rrs r4 mapFromDatazImageItem.mapFromDatas"&&s+++r5.Ac|j}|dkrd} |jdd\}}||z|krn&||kr|dddddf}n|dddddf}B|j||j|fS)a Estimates the min/max values of the image data by subsampling. Subsampling is performed at regular strides chosen to evaluate a number of samples equal to or less than `targetSize`. Returns (`min`, `max`). rTN)rrCr%nanminnanmax)r2rrnhws r4rzImageItem.quickMinMaxsz >>J %:bqb>DAq1u ""E1uuCCaCG}BBB!G}  %xt$$dhood&;&;;;r5cNddi}|||j|i|S)NrF)r7r0)r2rr3defaultss r4rVzImageItem.updateImages; %  t}d/h///r5cd|_|j|jjdkrdS|jjdks|jjddkr|||j|j|_t|jtr5|||jd|j}n |j}nd}|j r| \}}|dS|j dkrddgnddg}tj|j||d}tj|||d}||f|_|jdkrdSn|j}|jdkr|jd dkr|d }|j d kr|dd}|j}|jH|jjd ko+|j||_d|_d}|2|j|jjkrt3jd t6dn|jst9j|||}n|jdvrx|jT|j|}|jdkr|d}||_t9j||||j}|%d|_ d|_!||_"d|_#d|_dS|j %|j jdd|jddkr|$|jtj%||||j |jtMkr |j '|j!tj(|j!tRj*j+j,|_"d|_#d|_dS)NTrrrr[ru)rErKr).rrAfzUsing non-uint8 LUTs is an undocumented accidental feature and may be removed at some point in the future. Please open an issue if you instead believe this to be worthy of protected inclusion in pyqtgraph.) stacklevel)rr)rrK)rrtransparentLocationsF)rroutput)out)-r$rsizerLrCrirr%r]rr_computeDownsampleFactorsr)r; downsampler swapaxesrr'rkindrminr(uint8warningswarnDeprecationWarningrtry_make_qimageanynonzeror!r"rr#rmakeARGBrr`ndarray_to_qimager QImageFormat Format_ARGB32) r2rxdsydsaxesrrrnanmasks r4renderzImageItem.renders! : A!5!5 F :?a  4:#3A#6!#;#;44TXtxHHDH$(H-- 33DHHTZ4M4MtxXXhC   5577HC{!^{::Aq66ADM$*cQ@@@EM%47;;;E$':D zQJE :??u{2!33&ME >[ ( (NN1a((E   %  C',uyy{{++  '+D # ?syDHN:: MY#q  2 2 2 2 2 # C%5eFPSTTTFF Z6 ! !&.(..//<1$$%kkqk11G*1//*;*;'%5eFPSjnkBCCCF  %)D ""&D  DK#(D !&D  F  ! )T-C-I"1"-MQVQ\]_^_]_Q`-`-`  # #EK 0 0 0 Es6$:PQQQQ 8wyy  " & &4+> & ? ? ?*4+> @S@abb $"r5cntj}|jdS|jr(||jrdS|d|j%||j|d|jdkr|jj ddn|jj ddddd}| tj ddg|R|j |d|jC||j||dSdS)Nz render QImagez set comp moderArrrz p.drawImage)rrrr#rr$rr9r)rC drawImager rQrr.setPendrawRectrS)r2prrrCs r4paintzImageItem.paintcsH."" :  F   % KKMMM!  GO $ $ $ > %  0 0 0 GO $ $ $(,+(E(E  !$$4:K[\^]^\^K_`d`dbd`dKe FM!A-u---t{;;;  ; " HHT[ ! ! ! JJt((** + + + + + # "r5cb|jr||jj|g|RdS)z Saves this image to file. Note that this saves the visible image (after scale/color changes), not the original data. N)r#rrsave)r2fileNamers r4rzImageItem.savews?    KKMMM )D))))))r5autoFc |j|jjdkrdS|dkrtdt|j|jjd|z tdt|j|jjd|z f}|j|r||f}|jdd|ddd|df}t|trX|dkrQ|j | }|j | } | |kr| dz } |j |s|j | rdS|jjdvr_t|j| |z dz }g}|dkr)|j|| d |zz|t }n|j|| d }t%|dkr|j|| f}||d <t)} |rg} t+|jd D]} |d| f} | |j| } |jj| fi|}| rR| | |ddd | |df| |ddd |df| S||j|}|jj|fi|} | r>| | ddd | | dfS| ddd | dfS)a Returns `x` and `y` arrays containing the histogram values for the current image. For an explanation of the return format, see :func:`numpy.histogram()`. The `step` argument causes pixels to be skipped when computing the histogram to save time. If `step` is 'auto', then a step is chosen such that the analyzed data has dimensions approximating `targetImageSize` for each axis. The `bins` argument and any extra keyword arguments are passed to :func:`numpy.histogram()`. If `bins` is `auto`, a bin number is automatically chosen based on the image characteristics: * Integer images will have approximately `targetHistogramSize` bins, with each bin having an integer width. * All other types will have `targetHistogramSize` bins. If `perChannel` is `True`, then a histogram is computed for each channel, and the output is a list of the results. NrNNrruig@@rPg)\(?rrbinsr.)rrmaxintr%ceilrCisscalarr]r_ritemrrrrarangelinspacerrUrrangeisfinite histogramappendasnumpy)r2rstep perChanneltargetImageSizetargetHistogramSizekwdsstepDatarrrhististepChanrs r4 getHistogramzImageItem.getHistograms, : A!5!5: 6>>3tx}}TZ-=a-@?-RSSTTUU3tx}}TZ-=a-@?-RSSTTUUWD 8  T " " $"-.. 3 3#CF+#DH$5$5h$?$?@&DH&x884883KKAaD"I!6!6 1Q48H8H IJJJJKK1crcAaD 12222K 1 1( ; ;||| |dSdSrk) buttonr Qt MouseButton LeftButtonignorer-acceptdrawAtposr2evs r4mouseDragEventzImageItem.mouseDragEventsn 99;;&)/: : : IIKKK F _ ( IIKKK KK" % % % % %) (r5cn|tjjjkr)||r||jV|tjjjkr,| | |dSdSdSrk) rr rr  RightButtonraiseContextMenur#r-r!r$r%r&s r4mouseClickEventzImageItem.mouseClickEvents 99;;&)/; ; ;$$R((  ? &299;;&):O:Z+Z+Z KK" % % % % % ' &+Z+Zr5c ||}|dS||||}|}|t jt|t| dS)NFT) getMenusceneaddParentContextMenus screenPospopupr QPointrrr)r2r'rr%s r4r+zImageItem.raiseContextMenus||~~ <5zz||11$bAAllnn 6=SUUWWs35577||<<===tr5c|j|jsdStj|_|jt ddt jt dd|j}|j |j |j |||j_ |jS)NrImagez Remove image) rr/r QMenusetTitlerr QAction triggeredconnect removeClicked addActionremAct)r2r=s r4r.zImageItem.getMenus 9 > t!))DI I  yg>> ? ? ?]9[.#I#I49UUF   $ $T%7 8 8 8 I   ' ' '%DI yr5c|s|j}|tjjjrT|tjjj|tjjjdS|s2|j r-|tjjjdSdSdSrk) isExitr- acceptDragsr rr r! acceptClicksr*r/r&s r4 hoverEventzImageItem.hoverEvent$syy{{ ?t:r~~fiNcNn?o?o: OOFI1< = = = OOFI1= > > > > > ? ? OOFI1= > > > > > ? ? ? ?r5cdSrkrr&s r4 tabletEventzImageItem.tabletEvent+s r5ct|jdkrCt|t|g}nBt|t|g}|j}|j}d|jdg}d|jdg}|d|dz |d|dz |jdzg}|d|dz |d|dz |jdzg}dD]} td||  } td|jjd|| z } || xx| | zz cc<|| xx| | zz cc<td||  } td|jjd|| z } || xx| | zz cc<|| xx| | zz cc<t|d|dt|d|df}t|d|dt|d|df}|j }|}t|j tr!| ||j||||dS||}|j dkr7|*||}|j|d|z z||zz|j|<nC||j|<n8|j dkr|j|xx|z cc<ntd|j z|dS)NrArr)rrsetaddzUnknown draw mode '%s')r)rrrr-drawKernelCenterrCrrslicedrawMaskr]drawModer ExceptionrV)r2r%r'dkkcsxsytxtyrdx1dx2dy1dy2tsssmasksrcs r4r$zImageItem.drawAt1s >[ ( (suuww<<SUUWW.CCsuuww<<SUUWW.C _  " _ _!fr!unc!fr!unbhqk9 :!fr!unc!fr!unbhqk9 :  Aq"Q%==.Ca)!,RU233C qEEESW EEE qEEESW EEEq"Q%==.Ca)!,RU233C qEEESW EEE qEEESW EEEEBqE"Q%  %1be"4"4 5BqE"Q%  %1be"4"4 5} dmX . .  MM"dj$B ; ; ; ; ;b'C}%%#8D%)Z^qv%>t%KDJrNN%(DJrNN%'' 2#% 84= HIII        r5rrrFc>||_||_||_||_dSrk)r-rHrKrJ)r2kernelrYcenterr8s r4 setDrawKernelzImageItem.setDrawKernel]s#  &  r5ctj|_|jj|j|jddS)Nr)r QTimer removeTimertimeoutr:emitRemoveRequestedstartrMs r4r;zImageItem.removeClickedcsJ!=??  (()ABBB q!!!!!r5c|jj|j|j|dSrk)rbrc disconnectrdsigRemoveRequestedrrMs r4rdzImageItem.emitRemoveRequestedis<  ++D,DEEE $$T*****r5rk)Tr)rA)r)rrFrr)NNr[rF)8__name__ __module__ __qualname____doc__r Signalrobjectrhrr9r?rFrIrNrSrWrYrergrb staticmethodrirsr1r{rrr0r,rrrrrrVrrrrr r rrrrr(r,r+r.rBrDr$r_r;rdrr5r4rrsb$fmooO&v..)")")")"V>&&& &&& BBB PPP 2GGG" ####$  \     @@@@D2a%a%a%a%F3333 # # # * * *333,,,<<<<( 0 0 0_#_#_#B,,,(***X[),I-I-I-I-VJJJ444BBB    : : :&&&&&&   ???   ****X """ +++++r5)rcollections.abcrrmrrrr;rr r rr r r util.cupy_helperrrQCoreApplicationr__all__rrr5r4rus'$$$$$$ ))))))))))&&&&&&******  # - -V +V +V +V +V +V +V +V +V +V +r5