Code covered by the BSD License  

Highlights from
imagescnan.m v2.1 (Aug 2009)

4.66667

4.7 | 9 ratings Rate this file 36 Downloads (last 30 days) File Size: 5.76 KB File ID: #20516
image thumbnail

imagescnan.m v2.1 (Aug 2009)

by

 

30 Jun 2008 (Updated )

Same as IMAGESC but ignores NaNs.

| Watch this File

File Information
Description

Syntax:
>> imagescnan(Z) % Uncolored NaNs
>> imagescnan(Z,'k') % Colored

IMAGESC is a good option when the user doesn't like the interpolating behaviour of SURF or PCOLOR, because EVERY element is drawn as a single pixel CENTERED with the axis value.

The problem with this function is that it doesn't work properly with NaNs elements (although sometimes SURF neither does): they are drawn with the lower color of the current colormap.

This functions uses IMAGESC but ignores the NaNs elements.

The user can specify the NaNs color, a different color mask, or another value to be ignored.

If the user gives X and Y data with no constant increment, PATCH is used instead of IMAGESC (this is experimental!).

To freeze the colormap check COLORFREEZE and CBFREEZE here at the FileExchange.

(Bugs reports and suggestions will be very appreciated)

Acknowledgements

Image Overlay, Spyx.M, Ndnanfilter.M, and Freeze Colors / Unfreeze Colors inspired this file.

MATLAB release MATLAB 7.7 (R2008b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (23)
24 Sep 2013 Noah Levine-Small

The mirrored axis problem is a general matlab bug. Try setting opengl to software.

08 Mar 2012 Ste  
02 Mar 2012 Nicolas Beuchat

Excellent function, I had a little function that put the NaN white but this one is much more flexible! Thanks!

03 Feb 2012 Mario Trevino

gracias!

08 Apr 2011 Felipe G. Nievinski

why not do simply:
imagesc(img, 'AlphaData',~isnan(img))
where, e.g.,
img = membrane(1,25);
img(1:10:end) = NaN;

11 Mar 2011 Kaushik

Hi, thanks a lot this was very helpful. However, as Camille has pointed out, the axis lebels appear mirrored at times. This doesnt happen all the time, but mostly at times when there are too many NaNs in the Matrix. Is there a workaround?

17 Dec 2010 Camille Couzi

Hi again, I am having the same problem as Yu-nung Nina in 2009:
"Axis labels of both axes flip (the numbers become "mirror image" of normal axis tick labels) "
Please can you write here what solution you found to that problem?
Thanks a lot
Camille.

17 Dec 2010 Camille Couzi

Millones de gracias por esta herramienta super util y facil de usar!!!!

14 Dec 2009 Cesare  
17 Nov 2009 Carlos Adrian Vargas Aguilera

Yes Olivier, or with:
>> imagesc(U,'AlphaData',~isnan(U),'AlphaDataMapping','none')
I just wanted to be able to paint NaNs with specifyc color without modifying the axes color.
Probably I should include this "transparent" option. Thank you!

Carlos

17 Nov 2009 Olivier Ripoll

another way to obtain this is simply (fo a given array M):

alpha(imagesc(M),double(~isnan(M)))

You can of course get all the imagesc options since you can it directly.

27 Jun 2009 Ben  
13 Jun 2009 David Wang

Anyway, that won't make life easier. Probably I should simply do this:

pcolor((x(1:end-1)+x(2:end))/2, (y(1:end-1)+y(2:end))/2, c(2:end,2:end));

It's not perfect. The first/last column/row get dropped. But it should be sufficient for my use...

13 Jun 2009 David Wang

Thanks for your response, Saludos.

First, PCOLOR(X,Y,C) regards X,Y as the edges of pixels, while IMAGESC(X,Y,C) regards X,Y as the centers of pixels. The latter is what I need.

Second, what I want is not 'interp' but 'faceted', namely facet lines at the edges of pixels, which is what PCOLOR does by default:
http://www.mathworks.com/access/helpdesk/help/techdoc/ref/pcolor1.gif

D.

11 Jun 2009 Carlos Adrian Vargas Aguilera

Yes (kind of) but first, why would you like to do so if you can do it with PCOLOR? Well...

% Change line 359:
if aequal
%by:
if 0

% On empty line 398 write:
U = [U U(:,end); U(end,:) U(end,end)];
% Which is the trick. You may try other ways.

% Finally, change line 404:
'FaceColor','flat',...
% by:
'FaceColor','interp',...

% And that is it. Try imagescnan(peaks(5)) and you'll see the problem, which is that the interpolation is done on the edges and not on the middle of the faces (sort of). Maybe some day...

Saludos, Carlos Vargas

11 Jun 2009 David Wang

This is a great script. I've got a relevant question. Do you know if it is possible to make imagesc/imagescnan draw facet lines as shading facets applies to pcolor?

Thanks!

09 Jun 2009 Carlos Adrian Vargas Aguilera

I guess not Yu-nung, the program may flip the image if your axes are decreasing, but never the ticks. Try a normal IMAGESC or send me your script. Carlos

09 Jun 2009 Yu-nung Nina

One small mistake in my comment: on my personal laptop, the plot looks normal WITHOUT these two bizard things happening.

09 Jun 2009 Yu-nung Nina

Hi, this script is fantastic. However, I found 2 strange things happen:

1. Axis labels of both axes flip (the numbers become "mirror image" of normal axis tick labels)
2. When I try to plot a matrix of size 420x810, the plot does not complete itself. Instead the script only plots the first few rows and stops.

These two things happen on my lab computer (with matlab R2006a, R2008a, R2008b on it; I tried all of them). But on my personal laptop, the plot looks normal with these two bizard things happening. Is there any special settings in your code that is related to the computer itself?

13 Aug 2008 Gus Silva

This problem has been bothering me for a very long time. Thanks allot!!!

11 Jul 2008 Carlos Adrian Vargas Aguilera

Thank you very much Greg!, I already sent and updated file, which also accepts RGB images.

Cheers, Carlos

11 Jul 2008 Greg King

imagescnan did just what I wanted (i.e., color NaNs white). However, exploring the color option I found a bug. The doc says that "color" can be a 3 element vector or a character ('k', 'w', etc). In fact only the latter option works. The 3 element color vector results in an error.

01 Jul 2008 Carlos Adrian Vargas Aguilera

I submited an updated file that freezes correctly the colorbar.

Carlos Vargas

Updates
02 Jul 2008

Now the COLORBAR has a FROZEN colormap too.

08 Jun 2009

V2.0. Totally rewritten code. Do not converts to RGB anymore. Do not freezes the colormap anymore. Do not output any colorbar. New X and Y variable steps accepted input. Now uses patches.

20 Aug 2009

v2.1 Fixed BUG related with RGB image input.

Contact us