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

5 次查看(过去 30 天)
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?
  3 个评论
Luca Amerio
Luca Amerio 2018-4-9
I investigated it a little more and what seams to matter is the ration y(2)/y(1) (or x(2)/x(1) ).
The command works until the ration is smaller than 398.999999999999971578...

请先登录,再进行评论。

采纳的回答

Luca Amerio
Luca Amerio 2018-4-17

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

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

更多回答(1 个)

Walter Roberson
Walter Roberson 2018-4-9
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.
  7 个评论
Walter Roberson
Walter Roberson 2018-4-10
What I had observed in the past was that MATLAB continues to use the linear formula for the purpose of prediction of whether to draw the image or not, but that once it comes to draw the image, it just draws it linearly as if log axes were not in effect. I did not check this out in detail, though.
Years ago I posted,
"When the fixed half pixel outside margin is translated to coordinates in log space, the result can be outside of the current XLim. When that happens, the image is largely clipped out. If you set the XLim manually and then adjust the XData to be close to but not quite at the XLim, the image will occupy most of the plot space, disappearing if the margin would project over the XLim."
Luca Amerio
Luca Amerio 2018-4-17
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

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Images 的更多信息

标签

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by