imagesc() Y Axis Log Scale Not Working (Help!)

77 ビュー (過去 30 日間)
Yi
Yi 2015 年 9 月 17 日
コメント済み: Peter Jack 2018 年 12 月 6 日
I have a matrix (image_spectrogram) which representing a image.
Using the imagesc function, I can shown the image.
eg: imagesc(x,y,log10(image_spectrogram+1));
I am trying to set the y axis to log scale, so I typed:
set(gca,'YScale','log','YDir','normal','YTick',[0.1,100,500,1000,5000]);
However, it turns out that this is a fake log scale.
The YScale did turn into log scale, but the image is absolutely identical to the linear one.
Two images are attached as following.
How to get a real log scale (y axis) image, please help me! This is the linear image:
This is the Y axis log scale image:
They are same except the fake log scale Y axis.
My original code is :
imagesc(x,y,log10(image_spectrogram(1:floor(Fs/2),:)+1));
cmap = colormap('gray');
colormap(flipud(cmap));
caxis(log10([0.9,max(image_spectrogram(:))*0.2]));
set(gca,'YScale','log','YDir','normal','YTick',[0.1,100,500,1000,5000]);
Help!

採用された回答

Mike Garrity
Mike Garrity 2015 年 9 月 17 日
編集済み: Mike Garrity 2015 年 9 月 17 日
The way images work is that they only have coordinates for the corners. These get transformed and then the graphics hardware fills in the interior of the image using the texturemapping hardware. The texture lookup is linear (actually the ratio of two linear interpolations, but that doesn't matter here), so making one of the scales log has no effect on the interior of the image.
To get the interior of the image to transform non-linearly, you need coordinates for the interior vertices, rather than just colors. The pcolor command is the simplest way to do this:
h = pcolor(x,y,log10(image_spectrogram(1:floor(Fs/2),:)+1));
h.EdgeColor = 'none';
What pcolor is doing is actually creating a surface object and setting the view so that you're looking down from the top. It is important to note that the surface object is going to consume more memory than the image object would. That's because it actually has coordinates for all of the interior vertices.
  4 件のコメント
Yi
Yi 2015 年 9 月 17 日
Thank you very much. That works good!
Harley Day
Harley Day 2017 年 11 月 13 日
Thank you so much! I've been poking around with imagsc() for ages not realising the axes log wasn't working. My code now works perfectly.

サインインしてコメントする。

その他の回答 (3 件)

Oliver Woodford
Oliver Woodford 2015 年 9 月 17 日
If you want to avoid pcolor, you can resample the image at the log scale locations, then use imagesc to display that.
  1 件のコメント
Peter Jack
Peter Jack 2018 年 12 月 6 日
can you tell me how we can do that i.e resample existing image cdata at log scale location?

サインインしてコメントする。


Constantino
Constantino 2018 年 11 月 1 日
I cannot get to implement correctly neither of the two solutions given here. I just wanted to make a quick image from a "rows x columns" matrix, where the Y axis must be plotted in log scale. I thought it would be simple, but it seems matlab has so much complexity that my approach is not working.
image(My2DMatrix,'CDataMapping','scaled')
works fine. I can change the color scale, axes ranges, and everything through the menus from the created image. However, transforming the image so it displays a log Y axis does nothing to the image. Maybe I need another type of plot? I'm a complete newbe in matlab. Have worked with other languages but it seems matlab is not so easy as other programming environments.

Constantino
Constantino 2018 年 11 月 2 日
Ok, I solved my problem using contourf, which handles better my type of data

カテゴリ

Help Center および File ExchangeGraphics Object Properties についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by