<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	
	>
<channel>
	<title>
	Comments on: Auto-scale image colors	</title>
	<atom:link href="https://undocumentedmatlab.com/articles/auto-scale-image-colors/feed" rel="self" type="application/rss+xml" />
	<link>https://undocumentedmatlab.com/articles/auto-scale-image-colors?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=auto-scale-image-colors</link>
	<description>Professional Matlab consulting, development and training</description>
	<lastBuildDate>Thu, 22 Feb 2018 15:18:47 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.7.3</generator>
	<item>
		<title>
		By: Peter Cook		</title>
		<link>https://undocumentedmatlab.com/articles/auto-scale-image-colors#comment-419269</link>

		<dc:creator><![CDATA[Peter Cook]]></dc:creator>
		<pubDate>Thu, 22 Feb 2018 15:18:47 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=7334#comment-419269</guid>

					<description><![CDATA[Great utility. I do something quite similar in one of my applications. A couple remarks:

1. If the user of this function has read your &quot;&lt;a href=&quot;http://undocumentedmatlab.com/books/matlab-performance&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Accelerating MATLAB Performance&lt;/a&gt;&quot; book, it&#039;s likely they have set the &lt;b&gt;CLimMode&lt;/b&gt; of the parent axes and (if using a colorbar) the &lt;b&gt;LimitsMode&lt;/b&gt; property of the colorbar axes peer to &lt;code&gt;&#039;manual&#039;&lt;/code&gt;. If the listener triggers the callback like this, the colorbar will display color ranges correctly but will look kind of funny (as it retains previous limits) so replacing &lt;pre lang=&quot;matlab&quot;&gt;hAxes.CLim = CLim;&lt;/pre&gt; with &lt;pre lang=&quot;matlab&quot;&gt;[hAxes.CLim, hCb.Limits] = deal(CLim);&lt;/pre&gt; would be necessary. 

2. It may be the case that XData and YData are mapped to some values that don&#039;t round nicely (like datetime/MATLAB serial datetime), so the fix() function will cause problems. There&#039;s a couple cases to consider - in what you&#039;ve shown, the XData and YData are mapped to integer image indices and this function works fine even though XData and YData are (1x2) arrays. A less desirable case would be mapped XData and YData, but with only corners specified so that XData and YData are (1x2) arrays, but are not integers and may not fix nicely. If an (mxn) CData array is mapped to (mx1) YData and (nx1) XData then logical masking works i.e. 
&lt;pre lang=&quot;matlab&quot;&gt;
CData = hImage.CData(hImage.YData&gt;=hAxes.YLim(1) &amp; hImage.YData&lt;=hAxes.YLim(2), ...
                     hImage.XData&gt;=hAxes.XLim(1) &amp; hImage.XData&lt;=hAxes.XLim(2));
CData = CData(:);
&lt;/pre&gt;

3. For threshold values, depending on the dynamic range of the CData and zoom level the user has chosen, it may be safer to say &lt;pre lang=&quot;matlab&quot;&gt;thresholdIdx = [ceil(threshold*numel(CData)), floor((1-threshold)*numel(CData))]&lt;/pre&gt; to avoid the occasional zero-index attempt error.]]></description>
			<content:encoded><![CDATA[<p>Great utility. I do something quite similar in one of my applications. A couple remarks:</p>
<p>1. If the user of this function has read your &#8220;<a href="http://undocumentedmatlab.com/books/matlab-performance" target="_blank" rel="nofollow">Accelerating MATLAB Performance</a>&#8221; book, it&#8217;s likely they have set the <b>CLimMode</b> of the parent axes and (if using a colorbar) the <b>LimitsMode</b> property of the colorbar axes peer to <code>'manual'</code>. If the listener triggers the callback like this, the colorbar will display color ranges correctly but will look kind of funny (as it retains previous limits) so replacing </p>
<pre lang="matlab">hAxes.CLim = CLim;</pre>
<p> with </p>
<pre lang="matlab">[hAxes.CLim, hCb.Limits] = deal(CLim);</pre>
<p> would be necessary. </p>
<p>2. It may be the case that XData and YData are mapped to some values that don&#8217;t round nicely (like datetime/MATLAB serial datetime), so the fix() function will cause problems. There&#8217;s a couple cases to consider &#8211; in what you&#8217;ve shown, the XData and YData are mapped to integer image indices and this function works fine even though XData and YData are (1&#215;2) arrays. A less desirable case would be mapped XData and YData, but with only corners specified so that XData and YData are (1&#215;2) arrays, but are not integers and may not fix nicely. If an (mxn) CData array is mapped to (mx1) YData and (nx1) XData then logical masking works i.e. </p>
<pre lang="matlab">
CData = hImage.CData(hImage.YData>=hAxes.YLim(1) &#038; hImage.YData<=hAxes.YLim(2), ...
                     hImage.XData>=hAxes.XLim(1) &#038; hImage.XData<=hAxes.XLim(2));
CData = CData(:);
</pre>
<p>3. For threshold values, depending on the dynamic range of the CData and zoom level the user has chosen, it may be safer to say </p>
<pre lang="matlab">thresholdIdx = [ceil(threshold*numel(CData)), floor((1-threshold)*numel(CData))]</pre>
<p> to avoid the occasional zero-index attempt error.</p>
]]></content:encoded>
		
			</item>
	</channel>
</rss>
