image(x,y,A) fails on log axis depending on axis's limits
Mostra commenti meno recenti
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 Commenti
Guillaume
il 9 Apr 2018
Well, that's certainly interesting. Unfortunately, since image is a built-in function we can't look at the cause for the error. You would be better off raising a bug report with mathworks.
You can get the same problem by changing the YData property of your first image object:
figure
A = rand(200,200,3);
axes('XScale','log','YScale','log')
hold on
im = image([1e1 1e2],[1e2 1e4],A) %OK
im.YData = [100 1e5] %kaboom!
Luca Amerio
il 9 Apr 2018
Luca Amerio
il 9 Apr 2018
Modificato: Luca Amerio
il 9 Apr 2018
Risposta accettata
Più risposte (1)
Walter Roberson
il 9 Apr 2018
0 voti
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 Commenti
Luca Amerio
il 9 Apr 2018
Walter Roberson
il 9 Apr 2018
"Two-element vector — Use the first element as the location for the center of CData(1,1) and the second element as the location for the center of CData(m,n), where [m,n] = size(CData). Evenly distribute the centers of the remaining CData elements between those two points.
The height of each pixel is determined by the expression:
(YData(2)-YData(1))/(size(CData,1)-1)"
For the case giving you trouble that would be (1e5-1e2)/(200-1) so the pixel centers are 502.010050251256 apart. The edge would be 1e2-(502.010050251256/2) = -151.005025125628
If we do
syms y
solve(eps==1e2-(y-1e2)/199/2)
ans =
89846812566041395001/2251799813685248
>> vpa(ans)
ans =
39899.999999999999911626247239838
which is to say just slightly less than 4E4: an upper bound greater than that will result in the lower edge being below zero for an image with 200 pixels.
Walter Roberson
il 9 Apr 2018
Notice that https://www.mathworks.com/help/matlab/ref/image.html#buqdlnb-y specifically talks about centers, not about edges.
Luca Amerio
il 10 Apr 2018
Luca Amerio
il 10 Apr 2018
Walter Roberson
il 10 Apr 2018
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
il 17 Apr 2018
Categorie
Scopri di più su Image Arithmetic in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
