Skip to content

Commit

Permalink
Issue 575: add the WeightedSum filter and help about RGB histograms (#…
Browse files Browse the repository at this point in the history
…576)

* add WeightedSum filter

* add help about RGB histograms

* update manpage
  • Loading branch information
jkotan authored Sep 28, 2021
1 parent 43ee65d commit fa5fa68
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 3 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2021-09-28 Jan Kotanski <jan.kotanski@desy.de>
* add WeightedSum filter
* add help about RGB histograms
* tagged as 2.67.0

2021-09-21 Jan Kotanski <jan.kotanski@desy.de>
* make labels of intensity levels dynamic in the RGB mode
* add setting intensity channel levels from command line interface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ <h1 id="title-heading" class="pagetitle">

</div>
<div id="main-content" class="wiki-content group">
<p>In <strong>Display levels and colors</strong> user sets mapping between image pixel intensities and displayed colors on the 2D plot.</p><p><span class="confluence-embedded-file-wrapper confluence-embedded-manual-size"><img class="confluence-embedded-image" src="attachments/98091959/109161805.png" data-image-src="attachments/98091959/109161805.png" data-unresolved-comment-count="0" data-linked-resource-id="109161805" data-linked-resource-version="1" data-linked-resource-type="attachment" data-linked-resource-default-alias="autolevels_lavue.png" data-base-url="https://confluence.desy.de" data-linked-resource-content-type="image/png" data-linked-resource-container-id="98091959" data-linked-resource-container-version="13"></span></p><ul><li><strong>scaling:</strong> <code>sqrt</code>, <code>linear</code> or <code>log</code> – basic intensity scale for 2D images<br/> applied to<code> Image Statistics/1D plot</code> or not  – depending on <code>Configuration</code></li><li><strong>Levels:</strong> maximum and minimum intensity displayed. It can be automatic or set by user</li><li><strong>Auto levels %: </strong>switch to automatic levels settings. You can provide the levels as a cut factor in % of the highest pick.</li><li><strong>Bin edges:</strong> bin edges algorithm for finding histogram levels</li><li><strong>Step:</strong> step parameter for the bin edges algorithm for finding histogram levels</li><li><strong>Histogram:</strong> set intensity levels and color gradients on histogram plot</li><li><strong>Color gradients:</strong> 12 various basic settings with possibility to adjust with ticks</li></ul><p>By clicking the right-mouse-button on the color gradient bar you can <strong>save</strong> or <strong>remove</strong> your current<strong> customize color gradient </strong>into the local configuration (only in the expert mode).</p><p>For <strong>multi-channel images</strong> user can select a separate <strong>color channel</strong>, a <strong>sum</strong> or <strong>mean</strong> of all color channels or an <strong>RGB</strong> view.</p>
<p>In <strong>Display levels and colors</strong> user sets mapping between image pixel intensities and displayed colors on the 2D plot.</p><p><span class="confluence-embedded-file-wrapper confluence-embedded-manual-size"><img class="confluence-embedded-image" src="attachments/98091959/109161805.png" data-image-src="attachments/98091959/109161805.png" data-unresolved-comment-count="0" data-linked-resource-id="109161805" data-linked-resource-version="1" data-linked-resource-type="attachment" data-linked-resource-default-alias="autolevels_lavue.png" data-base-url="https://confluence.desy.de" data-linked-resource-content-type="image/png" data-linked-resource-container-id="98091959" data-linked-resource-container-version="13"></span></p><ul><li><strong>scaling:</strong> <code>sqrt</code>, <code>linear</code> or <code>log</code> – basic intensity scale for 2D images<br/> applied to<code> Image Statistics/1D plot</code> or not  – depending on <code>Configuration</code></li><li><strong>Levels:</strong> maximum and minimum intensity displayed. It can be automatic or set by user</li><li><strong>Auto levels %: </strong>switch to automatic levels settings. You can provide the levels as a cut factor in % of the highest pick.</li><li><strong>Bin edges:</strong> bin edges algorithm for finding histogram levels</li><li><strong>Step:</strong> step parameter for the bin edges algorithm for finding histogram levels</li><li><strong>Histogram:</strong> set intensity levels and color gradients on histogram plot</li><li><strong>Color gradients:</strong> 12 various basic settings with possibility to adjust with ticks</li></ul><p>By clicking the right-mouse-button on the color gradient bar you can <strong>save</strong> or <strong>remove</strong> your current<strong> customize color gradient </strong>into the local configuration (only in the expert mode).</p><p>For <strong>multi-channel images</strong> user can select a separate <strong>color channel</strong>, a <strong>sum</strong> or <strong>mean</strong> of all color channels or an <strong>RGB</strong> view.</p><p>With <strong>Map images to color channels</strong> in  <code>Configuration/General </code>checked on the user can adjust intensity display levels for each image sources separately on <strong>RGB</strong> <strong>histogram</strong>,e.g.</p><pre>$ lavue -s test\;tangoattr -c \;sys/tg_test/1/double_image_ro -i linear --channel rgb -l green -x</pre><p>lunches lavue with two image sources: test and sys/tg_test/1/double_image_ro tango attribute</p><p><span class="confluence-embedded-file-wrapper confluence-embedded-manual-size"><img class="confluence-embedded-image" src="attachments/98091959/226033522.png" data-image-src="attachments/98091959/226033522.png" data-unresolved-comment-count="0" data-linked-resource-id="226033522" data-linked-resource-version="2" data-linked-resource-type="attachment" data-linked-resource-default-alias="lavue_rgbhistogram.png" data-base-url="https://confluence.desy.de" data-linked-resource-content-type="image/png" data-linked-resource-container-id="98091959" data-linked-resource-container-version="22"></span></p><p>The test image source in the red channel has the intensity maximal value ~30 times larger than the tango image source image.  With the RGB histogram lavue adjusts the intensity levels separately for the each color channel so both images are visible in one time.</p><p>Other option to make both image visible is to use the <strong>WeightedSum </strong>filter from lavuelib.plugins.filters which performs the weighted sum of all channel images. </p><p><br/></p>
</div>

</div><section><!-- <div class="pageSection group">
Expand Down
Binary file added lavuelib/help/attachments/98091959/226033522.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
44 changes: 44 additions & 0 deletions lavuelib/plugins/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,47 @@ def rot45(image, imagename, metadata, imagewg):
and np.isnan(image.min()):
image = np.nan_to_num(image)
return ndimage.rotate(image, 45)


class WeightedSum(object):

""" Weighted sum of channel images"""

def __init__(self, configuration=None):
""" constructor
:param configuration: JSON list of channel image weights
:type configuration: :obj:`str`
"""
#: (:obj:`list` <:obj: `str`>) list of indexes for gap
self.__weights = [
wg for wg in json.loads(configuration or "[]")]

def __call__(self, image, imagename, metadata, imagewg):
""" call method
:param image: numpy array with an image
:type image: :class:`numpy.ndarray`
:param imagename: image name
:type imagename: :obj:`str`
:param metadata: JSON dictionary with metadata
:type metadata: :obj:`str`
:param imagewg: image wigdet
:type imagewg: :class:`lavuelib.imageWidget.ImageWidget`
:returns: numpy array with an image
:rtype: :class:`numpy.ndarray` or `None`
"""
if hasattr(image, "shape") and len(image.shape) == 3:

weights = np.array(
[(self.__weights[i]
if (len(self.__weights) > i and
type(self.__weights[i]) in [int, float])
else 1)
for i in range(image.shape[0])])

if hasattr(np, "ma"):
image_m = np.ma.array(image, mask=np.isnan(image))
return np.ma.dot(image_m.T, weights).filled(np.nan).T
else:
return np.where(np.isnan(image), 0, image).T.dot(weights).T
1 change: 1 addition & 0 deletions lavuelib/qrc/resources.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
<file>../help/attachments/98092053/98093165.png</file>
<file>../help/attachments/98092035/98093137.png</file>
<file>../help/attachments/98091959/109161805.png</file>
<file>../help/attachments/98091959/226033522.png</file>
<file>../help/attachments/98091927/98092916.png</file>
<file>../help/attachments/148825375/148825391.png</file>
<file>../help/attachments/145596142/145596144.png</file>
Expand Down
2 changes: 1 addition & 1 deletion lavuelib/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@
""" release version """

#: (:obj:`str`) the live viewer version
__version__ = "2.66.2"
__version__ = "2.67.0"
16 changes: 15 additions & 1 deletion man/lavuelib.1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.\" Man page generated from reStructuredText.
.
.TH "LAVUELIB" "1" "Sep 21, 2021" "2.66" "lavuelib"
.TH "LAVUELIB" "1" "Sep 28, 2021" "2.67" "lavuelib"
.SH NAME
lavuelib \- lavuelib Documentation
.
Expand Down Expand Up @@ -309,6 +309,20 @@ constructor
.UNINDENT
.INDENT 0.0
.TP
.B class lavuelib.plugins.filters.WeightedSum(configuration=None)
Bases: \fI\%object\fP
.sp
Weighted sum of channel images
.sp
constructor
.INDENT 7.0
.TP
.B Parameters
\fBconfiguration\fP (\fI\%str\fP) \-\- JSON list of channel image weights
.UNINDENT
.UNINDENT
.INDENT 0.0
.TP
.B lavuelib.plugins.filters.rot45(image, imagename, metadata, imagewg)
rotate image by 45 deg
.INDENT 7.0
Expand Down

0 comments on commit fa5fa68

Please sign in to comment.