Commit Graph

68 Commits

Author SHA1 Message Date
KIU Shueng Chuan b5475cad6b warn about usage of non-uint8 LUTs 2021-09-08 09:52:46 +08:00
KIU Shueng Chuan 6763b14fb9 delegate float luts to makeARGB() 2021-09-07 00:04:42 +08:00
Martin Chase 1d40d50b89
push bullet lists over 2 spaces to get them to show up as such in the… (#1912)
* push bullet lists over 2 spaces to get them to show up as such in the docs

* separate the literal block from the bullet list
2021-07-21 07:12:35 -07:00
Ogi Moore 418a181691 Use built-in int as dtype 2021-06-25 08:45:02 -07:00
Ogi Moore 61dedcb4a5
Merge pull request #1794 from pijyoi/numba_lookup 2021-06-15 16:42:54 -07:00
Ogi Moore 3c352dd1a9 Fix documentation misalignment 2021-06-08 21:23:49 -07:00
Ogi Moore d455da9aec Use Qt6 Enum Namespace
This namespace appears to be valid in PySide2/PyQt5 5.12+ so we may as
well migrate to the newer namespace ourselves.
2021-06-08 21:23:49 -07:00
Nils Nemitz f002d70adc
Expose number of subsamples in ImageItem auto-level determination (#1638)
* exposed number of subsamples in auto-level determination

* Removing print statement at @NilsNemitz's request

* make levelSamples count pixels, not pixels * channels

* minimum number of samples can be 2 if we look at pixels anyway

* adjusted minimum levelSamples to 4: Otherwise a 2x2 image downsamples to a single pixel

* extended docstring for level to make the user aware of auto-level subsampling

* subsample towards square array for auto-leveling

* eliminated duplicated code between level downsampling and samples and QuickMinMax method

Co-authored-by: Ogi Moore <ognyan.moore@gmail.com>
2021-06-08 10:25:47 -07:00
Nils Nemitz 61f067bf7c
Add axis convenience methods and matrix display example (#1726)
* add axis convenient methods and matrix display example

* wrestled wayward space back into docstring

* color map names are case sensitive on Linux

* docstring fix for PlotItem

* protect AxisItem.linkToView from being obscured by DateAxisItem override

* replaced setOrigin method by promoted setPos and setScale

* made tri-state axes switching explicit

* reverted setRect behavior, documentation pass for ImageItem

* minor text adjustment

* implmented some suggested revisions

* fix input parsing for setRect and add tests so that I don't break it again

* don't try to re-add transform after clearing it

* changed example and doc image generators to pg.exec()

* removed commented-out code

* cleaned up transform eqaulity assertion

* restored devoured comment

* restored devoured comment
2021-06-07 07:44:19 -07:00
KIU Shueng Chuan 7499c3b375 clip values can be derived from lut shape
also makes it clear that indices won't be out of range
2021-05-22 11:34:20 +08:00
KIU Shueng Chuan 9426ef0391 don't rely on QImage-wrapped buffer being writable 2021-05-22 09:10:03 +08:00
KIU Shueng Chuan 03ddf92839 implement numba lookup 2021-05-22 08:23:47 +08:00
Martin Chase ac84f45787
callable luts still need to be put onto a substrate (#1791) 2021-05-20 07:22:49 -07:00
Martin Chase a91953e93d
Bypass makeARGB in some cases (#1786)
* refactor out _ndarray_to_qimage()

* combine levels back with lut

* make use of Grayscale8, RGB888 and Indexed8 QImage formats

Grayscale8 and RGB888 images are those that are ready for display
without further processing.

* add Grayscale16

* apply the efflut early for uint16 mono/rgb, uint8 rgb

* ndarray indexing is faster than np.take

* handle uint16 rgb(a) with no levels same as levels=[0, 65535]

* add support for Format_RGBA64

* fix: support colormaps of shape (h, 1)

* check ImageItem uint8 and uint16 QImage formats

* uint16 mono with rgb lut -> RGBX8888

* got width and height swapped in array dimensions

* set ImageItem as row-major

* no need to form a 1d 32-bit lut for array indexing

you can index (y, x) into a lookup table of shape (nentry, 3) or
(nentry, 4) and get an output of shape (y, x, 3) or (y, x, 4)

* Revert "no need to form a 1d 32-bit lut for array indexing"

This reverts commit 45cf3100de.

* distinguish between levels_lut and colors_lut

this allows uint16 images with user lut to be rendered as
Format_Indexed8

* uint8 (1-chan) images should always combine to efflut

this efflut will then be used for Indexed8 format color table.

previously, we would be taking a performance hit with doing a numpy
lookup with levels_lut.

* adapt benchmarks/makeARGB.py to renderImageItem.py

* restructure uint8 and uint16 codepaths

* normalize 1-chan images to ndim==2 earlier up

* refactor long code into functions

* bug: qimage may not be assigned

* fix: assign to self.qimage only if not None

* for uint16, do rescale rather than do levels_lut lookup

* cases 2,3 are already handled

i.e. no more using lut to do rescale of uint16 image data.

* rescale rgb images by computation, not by memory lookup

* setImage() does not take an output argument

* try to be cupy compatible

use "xp" instead of numpy module

* add numba to benchmarking

* fix: lut_big is dtype uint8 with more than 256 entries

* bug: applying colors_lut needs C-order

* support float with no nans

* fix: variable could be uninitialized

* add float32 format tests

* avoid explicitly forcing to C-contiguous

* cache effective lut only if combination took place

every one of the four branches now does its own return.
this makes it easier to follow.

* fix cupy benchmark : typo in renderQImage

* remove for loop of 1 iteration

* use float32 for floating point benchmark

* superceded by renderImageItem.py

* lint

* benchmark without lut conversion

* put the lut onto the substrate

* fix editor complaints

* handle lack of cupy

* leading underscores imply privacy

Co-authored-by: KIU Shueng Chuan <nixchuan@gmail.com>
2021-05-19 17:21:12 -07:00
Martin Chase 85e2574230
useCupy option should be settable after ImageItem init (#1749)
* do not cache the cupy so the config option can be set later

* getCupy will always return None if the option is not set

* test of failing behavior

* divorce skip from option; restore option after test
2021-04-30 10:41:11 -07:00
KIU Shueng Chuan 5df14aec1d combine levels and lut only if both are present
previously, if levels was present but lut was not, levels would be
converted into lut.
2021-03-13 16:27:20 +08:00
KIU Shueng Chuan 185f9c7dad remove scale, rotate and translate shims 2021-02-01 09:06:23 +08:00
Ogi Moore b54aa3914d
Attempt i18n localization (#1513)
* Trying translate on exporter strings

* Try translate on other misc context menu strings

* First f-string and I screw it up...

* add more translation calls
2021-01-27 11:34:32 -08:00
Martin Chase 1654cb62ac
Small ImageItem-related improvements (#1501)
* Initial asv configuration

* makeARGB benchmarks are working

* Fix array type checking and allow making QImage in greyscale mode

* Performance improvements

* benchmark minor update

* Add CLI args to video speed test for easier / automated benchmarking

* udpate asv conf

* use a buffer-qimage so we can avoid allocing so much

this should improve performance under windows

* Add CLI args to video speed test for easier / automated benchmarking

* use a buffer-qimage so we can avoid allocing so much

this should improve performance under windows

* playing with numba

* oh, mins/maxes in the other order

* maybe put the cupy in here and see what happens

* pre-alloc for gpu and cpu

* handle possibility of not having cupy

* no numba in this branch

* organize imports

* name them after their use, not their expected device

* cupy.take does not support clip mode, so do it explicitly

* add CUDA option to the VideoSpeedTest

* rename private attr xp to _xp

* handle resizes at the last moment

* cupy is less accepting of lists as args

* or somehow range isn't allowed? what histogram is this?

* construct the array with python objects

* get the python value right away

* put LUT into cupy if needed

* docstring about cuda toolkit version

* better handling and display of missing cuda lib

* lint

* import need

* handle switching between cupy and numpy in a single ImageItem

* only use xp when necessary

we can now depend on numpy >= 1.17, which means __array_function__-implementing cupy can
seamlessly pass into numpy functions. the remaining uses of xp are for our functions which
need to allocate new data structures, an operation that has to be substrate-specific.

remove empty_cupy; just check if the import succeeded, instead.

* use an option to control use of cupy

* convert cupy.ceil array to int for easier mathing

* RawImageWidget gets to use the getCupy function now, too

* raise error to calm linters; rename for clarity

* Add Generated Template Files

* document things better

* cruft removal

* warnings to communicate when cupy is expected but somehow broken

* Merge branch 'cupy-rebase' into 'l/imageitem-performance'

Abundant conflicts; accept theirs in nearly every case.

* playing with settings to suss out timeout

* playing with more stuff to suss out timeout

* replace with empty list

* skip test_ExampleApp on linux+pyside2 only

* clean out some bits that no longer make sense; linty

* ignore airspeed velocity dir

* lint

* tidy up for merge

* lint

* lint, avoid shadowing

* specific import; run-as-script setup

Co-authored-by: Luke Campagnola <luke.campagnola@gmail.com>
Co-authored-by: Ogi Moore <ognyan.moore@gmail.com>
2021-01-19 23:19:03 -08:00
Martin Chase f2b4a15b2d
Performance enhancement: use CUDA in ImageItem (#1466)
* Add CLI args to video speed test for easier / automated benchmarking

* use a buffer-qimage so we can avoid allocing so much

this should improve performance under windows

* playing with numba

* oh, mins/maxes in the other order

* maybe put the cupy in here and see what happens

* pre-alloc for gpu and cpu

* handle possibility of not having cupy

* no numba in this branch

* organize imports

* name them after their use, not their expected device

* cupy.take does not support clip mode, so do it explicitly

* add CUDA option to the VideoSpeedTest

* rename private attr xp to _xp

* handle resizes at the last moment

* cupy is less accepting of lists as args

* or somehow range isn't allowed? what histogram is this?

* construct the array with python objects

* get the python value right away

* put LUT into cupy if needed

* docstring about cuda toolkit version

* better handling and display of missing cuda lib

* lint

* import need

* handle switching between cupy and numpy in a single ImageItem

* only use xp when necessary

we can now depend on numpy >= 1.17, which means __array_function__-implementing cupy can
seamlessly pass into numpy functions. the remaining uses of xp are for our functions which
need to allocate new data structures, an operation that has to be substrate-specific.

remove empty_cupy; just check if the import succeeded, instead.

* use an option to control use of cupy

* convert cupy.ceil array to int for easier mathing

* RawImageWidget gets to use the getCupy function now, too

* raise error to calm linters; rename for clarity

* Add Generated Template Files

* document things better

* cruft removal

* warnings to communicate when cupy is expected but somehow broken

* playing with settings to suss out timeout

* playing with more stuff to suss out timeout

* replace with empty list

* skip test_ExampleApp on linux+pyside2 only

Co-authored-by: Luke Campagnola <luke.campagnola@gmail.com>
Co-authored-by: Ogi Moore <ognyan.moore@gmail.com>
2021-01-19 21:26:24 -08:00
miranis c5c41b9090
zero-step in np.arange (#1468) 2020-12-17 22:48:55 -08:00
Kenneth Lyons e78e9c256d Consolidate and fix downsample factor computation in ImageItem 2020-09-20 22:06:00 -07:00
ChristophRose ed009d3779 Check lastDownsample in viewTransformChanged
Add a check in the viewTransformChanged function to only force a rerender when the downsampling factor changed.
Previously simply moving the image around or zooming in/out without changing the downsampling factor would force a complete rerendering of the image, which was very slow with large images. This way, the expensive rerender is only forced if necessary.
2020-05-30 22:15:52 -07:00
2xB bfd36dc203 Prevent element-wise string comparison (code by @flutefreak7) (#1024) 2019-09-12 21:30:39 -07:00
2xB 4a592ef10e
Prevent element-wise string comparison
Issue #835 shows that comparing `bins`, which may be a numpy array, with a string `'auto'` leads to element-wise comparison, because the `==` operator for numpy arrays is used. With this commit, potential array and string are switched, so the `==` operator for strings is used, which does no element-wise comparison.
2019-06-17 19:10:32 +02:00
Kenneth Lyons deab37d533 Try to import from collections.abc for Python 3.3+ (#887)
* Try to import from collections.abc for Python 3.3+
2019-05-25 16:25:49 -07:00
Jim Crowell d261c2f0f2 fixed bug in graphicsItems/ImageItem.py: degenerate images (max==min) would raise exception in getHistogram() 2018-10-10 10:29:16 -04:00
Luke Campagnola efaf61f711
Merge pull request #541 from justengel/image_render_error
ImageItem render error if graph is too small.
2018-09-28 15:38:02 -07:00
Pol Welter d35991ec37 Fix issue #699
Nan in image data not handled properly
2018-06-01 15:05:14 +02:00
Luke Campagnola 748ca554e4
Merge pull request #675 from campagnola/fix-empty-image
Gracefully handle case where image data has size==0
2018-04-25 16:57:43 -07:00
Luke Campagnola 1206981107
Merge pull request #528 from HashSplat/master
Fixed downsample inf image issue
2018-04-25 16:32:02 -07:00
Luke Campagnola 0c1cda4973 Gracefully handle case where image data has size==0 2018-04-25 16:11:25 -07:00
Luke Campagnola a06ca1df29
Merge pull request #600 from miranis/patch-2
Update ImageItem.py
2018-01-29 20:36:09 -08:00
miranis 5d09746738 Update ImageItem.py
Functions nanmin and nanmax are defined in the numpy module and cannot be accessed from the global namespace!
2017-10-23 01:45:52 +02:00
Luke Campagnola c3e52f15b0 Fix ImageItem rgb histogram calculation 2017-10-03 08:16:36 -07:00
Luke Campagnola 07d1a62bfc ImageItem: add support for rgb handling by histogramlut 2017-09-26 08:31:28 -07:00
HashSplat 1ea4f5ab6f ImageItem render error if graph is too small.
Fixed issue where render would error because 'mapToDevice' would return None if the view size was too small.
2017-08-31 08:55:58 -04:00
HashSplat e7ba0ca272 Found that downsample would set the image size to 0 causing errors. 2017-08-08 15:35:54 -04:00
HashSplat 70831245a8 Fixed issue where ImageItem data size would be 0 due to colormap. 2017-08-08 14:58:33 -04:00
Luke Campagnola e87eaa652d Docstring correction 2017-07-14 15:10:04 -07:00
Luke Campagnola 152c5d393f Fixed bool / monochrome image display, added more unit tests 2016-09-07 17:56:00 -07:00
Luke Campagnola 748a8433b9 minor edits 2016-09-06 17:46:52 -07:00
Luke Campagnola db07a16913 Test update and more bugfixes 2016-08-31 15:15:44 -07:00
Luke Campagnola df691596a7 ROI tests pass with row-major axis order 2016-08-25 18:18:15 -07:00
Luke Campagnola a76fc37112 imageAxisOrder config option now accepts "row-major" and "col-major" instead of "normal" and "legacy"
ImageItems can individually control their axis order
image tests pass with axis order check
2016-08-23 09:10:26 -07:00
Luke Campagnola bee5878915 Added imageAxisOrder config option
Added global config documentation
ROIs don't exactly work yet..
2016-08-23 09:06:43 -07:00
Luke Campagnola 8b0c61ef01 Add ImageItem tests, fix image downsampling bug 2016-07-18 17:21:02 -07:00
Luke Campagnola 2a80205dd4 ImageItem bugfix 2016-01-30 09:52:37 -08:00
Luke Campagnola 70482432b8 Improve ImageItem performance by scaling LUT instead of image when possible.
Moved eq function from flowcharts to main function library to support this.
Bonus: fixed a flowchart bug (backspace deletes wrong connector) while I was in there.
2016-01-30 00:10:25 -08:00
fedebarabas ab1051f494 invalid slice fix 2015-09-04 19:21:38 -03:00