# image(x,y,A) fails on log axis depending on axis's limits

39 views (last 30 days)
Luca Amerio on 9 Apr 2018
Commented: Walter Roberson on 17 Apr 2018
Hi The question is pretty much self explanatory given the following example
The following code works:
figure
A = rand(200,200,3);
axes('XScale','log','YScale','log')
hold on
image([1e1 1e2],[1e2 1e4],A)
The following code doesn't work:
figure
A = rand(200,200,3);
axes('XScale','log','YScale','log')
hold on
image([1e1 1e2],[1e2 1e5],A)
The only difference between the two codes is the y coordinate of the top corner (1e4 in the first example, 1e5 in the second).
Why does this happen and how can I fix it?
Luca Amerio on 9 Apr 2018

Luca Amerio on 17 Apr 2018

From the MATLAB Technical Support:

---------------------------------------------------------------------------------------------------

Hello Luca,

I am writing in reference to your Technical Support Case #03035296 regarding 'image(x,y,A) fails on log axis depending on corner position'.

I apologize for taking some time to respond.

After collaborating with my colleagues, we have found that currently it is a bug at our end. Thank you for reporting this issue. I apologize for any inconvenience this may have caused you.

The issue lies in how an image object is rendered. MATLAB adds a small padding on all sides of the image to better support image visualization in cases where axis scale is linear. However, this padding currently is applied as a percentage of image dimension. Hence, causes the image to overflow in the invalid range of the log scale, namely, for negative values.

One possible workaround is to carefully manage the image "XData" and "YData" to make sure that the padding does not end up on the negative side of the log scale. The padding for "XData" is computed using 1/(2*imageDimInX) * (X2- X1). This should be restricted to be greater than "X1". Similarly for YData.

This padding is then added to "XData" and "YData" before being used for rendering.

Please be assured that the development team have been made aware of the issue and will consider it. They might consider fixing it in future releases of MATLAB.

Please feel free to reply to this mail if you have any other related questions. I will be happy to reopen this case and assist you further.

Sincerely, Niraj Gadakari MathWorks Technical Support Department

---------------------------------------------------------------------------------------------------

Walter Roberson on 17 Apr 2018
Ah, but what is the padding relative to ?

Walter Roberson on 9 Apr 2018
XData and YData are locations of pixel centers. You have to use the upper and lower values and the resolution to calculate where the lowest edge of the pixel would be. If it would be 0 or negative then the image cannot be displayed on a log plot.
Luca Amerio on 17 Apr 2018
At the end of the day, it turned out to be a bug in the image(...) function. See below for the full explanation of the Technical Support Team