Get from Ico-github-logo

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
SC - powerful image rendering

  • autumn(varargin)
    AUTUMN Red-yellow colormap
  • bled(varargin)
    BLED Black to red variation of the hsv colormap
  • bone(varargin)
    BONE Black-blue-white colormap
  • bone2(varargin)
    BONE2 Black-blue-white colormap
  • bright(varargin)
    BRIGHT Black-bright-white colormap
  • cold(varargin)
    COLD Black-blue-cyan-white colormap
  • colormap_helper(map, len,...
    COLORMAP_HELPER Helper function for colormaps
  • cool(varargin)
    COOL Cyan-magenta colormap
  • copper(varargin)
    COPPER Black-copper colormap
  • copper2(varargin)
    COPPER2 Black-copper-white colormap
  • dawn(varargin)
    DAWN Black-purple-blue-green-yellow-white colormap
  • disco(varargin)
    DISCO High contrast colormap with strong gradient discontinuities
  • disparity(varargin)
    DISPARITY High contrast colormap with subtle gradient discontinuities
  • dusk(varargin)
    DUSK Black-purple-blue-green-red-yellow-white colormap
  • earth(varargin)
    EARTH Black-green-white colormap
  • gray(varargin)
    GRAY Black-white colormap
  • hicontrast(varargin)
    HICONTRAST Black-blue-red-magenta-green-cyan-yellow-white colormap
  • hot(varargin)
    HOT Black-red-yellow-white colormap
  • hsv(varargin)
    HSV Red-yellow-green-cyan-blue-magenta-red colormap
  • hsv2(varargin)
    HSV2 Black to red variation of the hsv colormap
  • imdisp(I, varargin)
    IMDISP Display one or more images nicely
  • imsc(varargin)
    IMSC Wrapper function to SC which replicates display behaviour of IMAGESC
  • jet(varargin)
    JET Variant of HSV colormap
  • pastel(varargin)
    PASTEL Black-pastel-white colormap
  • pink(len, varargin)
    PINK Black-pink-white colormap
  • pink2(varargin)
    PINK2 Black-pink-white colormap
  • real2rgb(A, cmap, lims)
    REAL2RGB Converts a real-valued matrix into a truecolor image
  • rescale(A, lims, out_lims)
    RESCALE Linearly rescale values in an array
  • sc(I, varargin)
    SC Display/output truecolor images with a range of colormaps
  • sepia(varargin)
    SEPIA Black-brown-white colormap
  • spring(varargin)
    SPRING Magenta-yellow colormap
  • str2color(x)
    STR2COLOR Convert a color character to an RGB vector
  • summer(varargin)
    SUMMER Green-yellow colormap
  • temp(varargin)
    TEMP Blue-pale-dark red colormap
  • thermal(varargin)
    THERMAL Black-purple-red-yellow-white colormap
  • whed(varargin)
    WHED White to red variation of the hsv colormap
  • winter(varargin)
    WINTER Blue-green colormap
  • cache
    CACHE Wrapper class for caching slow-to-load data
  • imseq
    IMSEQ Open an image sequence as if it were a video stream.
  • imstream
    IMSTREAM Open an image or video stream for reading a frame at a time
  • View all files
4.8 | 38 ratings Rate this file 86 Downloads (last 30 days) File Size: 69.3 KB File ID: #16233 Version: 1.10
image thumbnail

SC - powerful image rendering



04 Sep 2007 (Updated )

Useful tool for rendering and outputting information rich images

| Watch this File

File Information

SC is a useful function for displaying rich image data, of use to anyone wishing to visualize and save 2D data in ways beyond that which MATLAB built-in functions allow.
This function can be used in place of IMAGE, IMAGESC and IMSHOW, but does so much more. It is fast and displays images as they should be - correct aspect ratio, integer magnification, no axes. In addition, it can return the image as an output variable - useful for saving to disk, texture mapping surfaces, and post-rendering manipulation such as overlaying/combining two or more images.
All the MATLAB built-in colormaps are implemented, but without MATLAB's nasty discretization artifacts. Plus, there are many new colormaps which are helpful for viewing more complex data, such as optic flow, likelihoods over images, difference images, segmentations, stereo image pairs (as anaglyphs) and edge-maps with orientation. It also accepts user defined linear and non-linear colormaps.
SC comes with a complete demo, to help you get the most out of it. It doesn't require that you have any toolboxes, either.

SC makes heavy use of two of my other file exchange packages, IMDISP (id 22387) and REAL2RGB (id 23342), which are both included in this package, but are very useful in their own rights too.

Please send queries or bug reports direct to me using the "Contact Author" link on my Author page.


Imdisp and Real2rgb & Colormaps inspired this file.

This file inspired Zerocolor, Cubehelix Colormaps: Beautiful, Distinct, Versatile!, and Color Brewer: Attractive And Distinctive Colormaps.

MATLAB release MATLAB 7.0.1 (R14SP1)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (74)
24 May 2016 S

S (view profile)

This is an excellent package and has solved many problems for me. Although I am a bit stuck on a recent one. I have an image and the results of an eyetracker, which I have processed with hist3, so I have my bins and the frequencies. I want to overlay the contourplot or heatmap over my image and I am trying to do it following the "gatlin" example but fail.. Any advice?

16 May 2016 S

S (view profile)

18 Feb 2016 Emma Stewart

06 Feb 2016 Xiangdong Zhao

20 Jul 2015 Pearl

Pearl (view profile)

23 Feb 2015 M B

M B (view profile)

Dear Oliver,

Great software!
I understand that I can use different colormaps for the "image" and the masked areas.
Is there a way to also use different "limits" (caxis) for the "image" and for the masked areas ?

19 Nov 2014 Zacharias Kandylakis

Hello! I am using the sc() function to overlay two images

1. a greyscale background
2. an image of pH levels with a custom colormap ( range of values is appr. 2.9 to 4 )

The visual result is as intended, however when I show the colorbar() I get the grayscale bar.
I need to show the custom map colorbar.
It is also important that the values are not scaled in 0-1 but remain at 2.9-4.

P.S. I have tried using built in cmaps such as 'prob','hot' and I have the same problem.

Comment only
14 Oct 2014 Oliver Woodford

as hz: Absolutely. A = sc(data). Read the help!

Comment only
14 Oct 2014 as hz

as hz (view profile)

Is there a way to store the image in memory so I can call it later by imshow?

Comment only
08 Oct 2014 Jon

Jon (view profile)

That's perfect - thanks, Oliver!

06 Oct 2014 Oliver Woodford

Jon: imsc can take the color scale as an input, so you just pass that in with the values you want. E.g.

imsc(mat3, [cmin cmax], 'jet', 'w', isnan(mat3));

Comment only
04 Oct 2014 Jon

Jon (view profile)

Hi there,

First off, Oliver, thanks for working so hard to create this sc package; I can see that it's benefited a lot of people, and it's clearly solving a problem encountered by many.

Next, a question: I'm using imsc to plot a matrix with several NaN values, but would like to use a color scale with a maximum and minimum different from the maximum and minimum values of the data. (I'm plotting several different matrices with different value ranges, and would like to use the same color scale for all of them.) I tried simply changing the minimum and maximum using the Colormap Editor, and that changed the extents of the colorbar, but didn't change the colors of the plotted data (i.e. the plotted data are now incorrect, relative to the colorbar). Is there any easy fix for this, using your function?

Here's the code I used to plot my data:

imsc(mat3, 'jet', 'w', isnan(mat3));

Thanks much,

Comment only
02 Aug 2014 Oliver Woodford

Amirali: Try clicking on the figure to select it, then pressing a key on the keyboard. The surface mesh example is given in the demo. The code is:
surf(Z, sc(Z, 'hicontrast'), 'edgecolor', 'none');
where Z is the heightmap.

Comment only
01 Aug 2014 Amirali

Dear Oliver
- When I run sc() the demo just plot fist gray figure and after press key nothing appears
(Using R2013a). How can I see other figures?
- How can I plot a 3d surface like that one you put in introduction image at top left of this web page (3d surface with axis at left- bottom of that image) ?
Best regards

Comment only
01 Aug 2014 Amirali

Dear Oliver
- When I run sc() the demo just plot fist gray figure and after press key nothing appears
(Using R2013a). How can I see other figures?
- How can I plot a 3d surface like that one you put in introduction image at top right of this web page (3d surface with axis at left- bottom of that image) ?
Best regards

Comment only
17 Jun 2014 Moritz

Moritz (view profile)

Dear Oliver,

all I needed was proper NaN treatment. I'm sure your function does a million other things, but you deserve a medal just for providing this.


29 Apr 2014 Matteo Niccoli

Why only 1 star?

28 Apr 2014 Oliver Woodford

Claudia: Just click the "Get from GitHub" button.

Comment only
28 Apr 2014 ClaudiaParise

28 Apr 2014 ClaudiaParise

Dear Oliver,

Please, how do I download the sc function?
I can see the comments but I am not able to find the link to get it.



Comment only
17 Mar 2014 TJ

TJ (view profile)

05 Feb 2014 Oliver Woodford

Javier: Both the help text and the demo provide the answer -
>> help sc
>> sc
This is what you want to use -
>> sc(cat(3, likelihood_img, img), 'prob')

Comment only
05 Feb 2014 Javier Montoya

Javier Montoya (view profile)

Hi Oliver, great work! I was wondering if you could give some examples on how to overlay likelihoods (MxMx1) into an RGB image (MxMx3). I tried something like: sc(img,cat(3,likelihood_img,likelihood_img,likelihood_img));
But didn't work out. Ideally, the output should look something like in the top-right figure of your webpage (Eli's example using `prob` and `probjet`):
Thank you!

Comment only
28 May 2013 Oliver Woodford

Abbas: The comments box is not the place for questions. Note that sc() and imsc() can take multiple masks, e.g.:
>> Z = peaks(256);
>> imsc(Z, 'jet', [0 0 0.5], Z>0&Z<0.2, [0 0 0.7], Z<-0.1&Z>-0.3);

Comment only
28 May 2013 Abbas

Abbas (view profile)

Dear Oliver

I have the digital elevation map of a region (dem1) and I am trying to flow two rivers with the codes of 1 and 0.5 in a new matrix named WetrSurf and overlay the WetSurf on dem1 to show the water flowing from two streams. It is possible to show one river but not for two:
When I have:
imsc(dem1,'jet',[0 0 128/255],(WetSurf==1));axis equal;axis image;axis ij;
title(['Flood Inundation: Iter = ' num2str(k) ', W-Lev = '...
num2str(WLE) 'm'],'FontSize',16);
It beautifully works but when I want to show those arrays of WetSurf with the value of 0.5 in the same image I will have problem. Please let me know how I can superimpose the second values of WetSurf (0.5) on the same topograpgy(dem1) simultaneously? Maybe I need to combine the following lines but I cant:

imsc(dem1,'jet',[0 0 128/255],(WetSurf==1));axis equal;axis image;axis ij;
title(['Flood Inundation: Iter = ' num2str(k) ', W-Lev = '...
num2str(WLE) 'm'],'FontSize',16);

imsc(dem1,'jet',[0 0 128/255],(WetSurf==0.5));axis equal;axis image;axis ij;
title(['Flood Inundation: Iter = ' num2str(k) ', W-Lev = '...
num2str(WLE) 'm'],'FontSize',16);

Best regards

Comment only
10 Apr 2013 Julia

Julia (view profile)


29 Jun 2012 SHAFIQUL

02 May 2012 bella

bella (view profile)

25 Apr 2012 Tao Han

07 Mar 2012 Oliver Woodford

Matthias: You can achieve that by setting the CurrentAxes property of the figure directly before calling SC. Alternatively, you can first draw the image in your GUI using IMAGE and save the image handle, then in the callbacks just set the CData property of the image using the output of SC. I do the latter, because it is faster at updating on screen.

Comment only
07 Mar 2012 Matthias Geissbuehler

Very nice framework! Works like a charm!
A little request which would make it even more useful: I would like to tell sc which axes-handle to use -> I would like to use it inside a GUI. is something like this imaginable? Or is sc not going to have enough flexibility in such a manner, since the axis position (&size) are going to be fixed? Any thoughts on this?

05 Jan 2012 Salmah Yasiran

Nice one!!

11 Nov 2011 Fabian

Fabian (view profile)

16 Aug 2011 Rafa

Rafa (view profile)

09 Aug 2011 Magnus

Magnus (view profile)

This is something of a stretch, but have you considered adding support for displaying CMYK-images? Otherwise, I love this function

Comment only
18 Jul 2011 Oliver Woodford

bmv: This is a problem with lipsol - any MATLAB function should be able to cope with the possibility sharing variable names with the names of functions on the path. I suggest you email the author, or fix it yourself.

Comment only
30 Jun 2011 bmv

bmv (view profile)

The name sc clashes with the Matlab file:

??? Error: File: lipsol.m Line: 987 Column: 7
"sc" previously appeared to be used as a function or command, conflicting with its use here as the name
of a variable.
A possible cause of this error is that you forgot to initialize the
variable, or you have initialized it implicitly using load or eval.

Comment only
26 May 2011 Harald Mayr

25 May 2011 Qianqian

Sorry, I have seen all the demos. This is a great tool.

25 May 2011 Qianqian

This is great. Just what I want. Would you please post an example here, which will make things easier for the user? Thank you very much. :)

Comment only
28 Feb 2011 Oliver Woodford

A note to all: SC only fills the figure completely with an image if the current axes is the default size. Therefore to avoid this behaviour, change the size of the axes first, e.g.:
set(gca, 'Position', [0.1 0.1 0.8 0.8]);

Comment only
28 Feb 2011 Brent Boehlert

Oliver: I sent you an email with an example. Let me know if you didn't receive it and I'll post it here.

Comment only
26 Feb 2011 Oliver Woodford

Brent: For help on this, please email me with an example figure and and print command.

Comment only
26 Feb 2011 Brent Boehlert

Hello Oliver,
Excellent work on this function. I have one issue -- when I print a figure to a .tif or .pdf, the colorbar labels on the right don't show up. If I move the outerposition of the figure over, they do, but then the left side of the image is cut off. Any thoughts on how to get the colorbar labels on my printed figure?

13 Jan 2011 Oliver Woodford

Camille: I think it's unlikely.

Comment only
22 Dec 2010 Camille Couzi

Hi, I left a message and it wasn't saved...
I sthat possible that nexplot property with replacechildren argument don't work for the same reason as the one told by Dove (and your answer about RGB images...)

Comment only
05 Dec 2010 Oliver Woodford

Dove: CAXIS only works on indexed images. The images generated by SC are RGB images (for various good reasons). There is an alternative - specify the range bounds in the call to SC. It's in the help text ("limits" argument).

Comment only
05 Dec 2010 Dove

Dove (view profile)

Hi Oliver,

I found that caxis is not working. Is there an alternative?

03 Nov 2010 Oliver Woodford

Camille: No. The tick functionality is the same as that of image. I suggest you contact the author of that submission to request support for images.

Comment only
02 Nov 2010 Camille Couzi

Hi! Is that possible to fix dateticks on this kind of image? I would need to apply dynamic date ticks (see, wich works on plot, but apparently not on imagesc and sc...
Thanks for reply!

Comment only
30 Aug 2010 Oliver Woodford

Patrik: SC draws the image into the current axes as a standard MATLAB image object. However, it doesn't return the handle of the image. You can get the handle either by using IMSC (which behaves more like MATLAB's IMAGESC) or by using FINDOBJ. If you use the correct handle this should work.

Comment only
30 Aug 2010 patrik

patrik (view profile)

Great function. I have one problem though; i want the user of my gui to be able to click in the figure a have drawn with SC and recieve pixel coordinates. However when I try to add a buttondownfunction by writing
set(sc_handle,'ButtonDownFcn',@get_pixel_value) i get an error;
Error using set. Invalid handle.
Does an sc-object not have the property ButtonDownFcn or what am I doing wrong?


19 Aug 2010 Oliver Woodford

C. Chaya & Justin: I've now included alternative to SC (called IMSC) which is the same as SC but with the display behaviour of IMAGESC, i.e. shows axes, variable aspect ratio etc.

Comment only
18 Aug 2010 Oliver Woodford

axis on

Comment only
17 Aug 2010 Camille Couzi

How can I set XTick, YTick, XTickLabel and YTickLabel VISBLE as they are not handle of the text object (as is Title for Example)?
Writting :
set(get(gca, 'XTickLabel'), 'Visible', 'on');

sends an error:
??? Error using ==> set
Value must be a handle

Error in ==> ploteo_postfiltrado at 56
set(get(gca, 'XTickLabel'), 'Visible', 'on');

Thanks a lot for the help :-)

Comment only
09 Jun 2010 Alize

Alize (view profile)

10 Dec 2009 K E

K E (view profile)

Helpful, thanks

12 Nov 2009 Ange

Ange (view profile)

12 Aug 2009 Oliver Woodford

Justin - if you prefer the image displaying properties of imagesc I suggest you use image(sc(X)). However, you then don't get the correct colorbar. If it's just the aspect ratio you don't like then call set(gca, 'DataAspectRatioMode', 'auto') after sc.

Comment only
12 Aug 2009 Justin

Justin (view profile)

The autopreservation of aspect ratio (mentioned by is the only thing I don't like about sc If I have a very long narrow matrix, imagesc scales it to display it in a standard sized matlab window. sc on the other hand gives me an extremely long narrow window. If there's an easy way to disable this please let me know.

Otherwise it's great.

30 Apr 2009 Jun wan

veri nice .bue i didn't try it

Comment only
18 Mar 2009 Idillus


18 Mar 2009 Yair Altman

Yair Altman (view profile)

Extremely well done: excellent documentation, very instructive online demo (look at its code: so clean and compact!), lots of boundary-condition checks and clever packing of lots of options into a decievingly-simple interface. Some of this submission's defaults should have been imagesc's as well (for example, auto preservation of aspect ratio & axes elimination, not to mention the discretization issues). I love it!

17 Mar 2009 Oliver Woodford

The problem with not displaying titles and axis labels has now been fixed, thanks to C. Chaya's suggestion.

Comment only
17 Mar 2009 Oliver Woodford

Removing the axes is a "feature" of the display side of this code. Unfortunately it does mean subplot titles and axes labels are hidden. This is something I've tried hard to avoid, but haven't found a way yet. You can use IMSHOW instead, but still get the benefits of SC, thus:
imshow(sc(X, 'jet'));

Comment only
16 Mar 2009 C. Chaya

Otherwise, an excellent job. would give it 4.5 stars if the rating system would let me.

Comment only
16 Mar 2009 C. Chaya

Doesn't show subplot titles. Must use

set(get(gca, 'Title'), 'Visible', 'on'); as a workaround.

28 Jan 2009 Andrew

Andrew (view profile)

Perfect. I used it to get around the fact that Matlab only allows one colormap per figure axis, and with some trial and error I even got the colorbar I wanted to show up. Great work Oliver.

15 Oct 2008 M HEMA NITHYA

04 Sep 2008 Ernesto Moya

It's great.

25 Mar 2008 Ross McGurk

Finally found a relatively simple tool for overlaying some deformation maps on a binary image.
Took me about half an hour to get it to do what I was hoping it would (and this was helped due one of the examples in the demo).

Thanks very much for making this available!

10 Jan 2008 Felix Hebeler

Excellent package, saved my day! Great support too! Highly recommended...

15 Nov 2007 p p

best viewing code ever

14 Nov 2007 John Henkel

This is a pretty good package. I was just about to resort to either Zedgraph or Python to make some really pretty contour graphs (gotta pull out all the stops to get more funding. =P ), and ran across this. Very nice, and easy to use. The demo is a neat feature.

05 Sep 2007

Improved description & title.
Added new Matlab colormaps to function.

05 Sep 2007

Improvements and a bug fix to the function

14 Sep 2007

Faster image display, numerous other improvements

18 Sep 2007

Fixed resize issue

24 Oct 2007

Reduced cyclic number of code.

26 Oct 2007

Updates seem to be revision behind.

15 Nov 2007

Added multiple screen support. Fixed truncation bug when displaying multiple images.

14 Jan 2008

Bug fix to 'prob_jet' colormap.

03 Mar 2008

Introduced 'flow' map, based on 'phase' map

04 Mar 2008

Bug fix to 'stereo'

04 Apr 2008

Fixed saturation issue with 'prob_jet'

16 Apr 2008

Added 'stereo_col'. Changed text a bit.

08 May 2008

Fixed saturation issue with 'phase'.
Leave axes on but make invisible, so TITLE etc. still work.

14 May 2008

Improved magnification to deal with images too large for the screen.

10 Dec 2008 1.1

Added ability for users to define linear and non-linear colormaps. Added ability to combine images within SC. Removed ability to display multiple images, as it isn't key functionality.

16 Dec 2008 1.2

Fixed typo in the description!

17 Mar 2009 1.3

Allow axis labels and titles, using fix suggested by C. Chaya.

17 Aug 2010 1.4

Overhaul of the function, making it a wrapper for real2rgb and imdisp, with the more complex colormaps added in (including some new ones).

19 Aug 2010 1.5

Added IMSC wrapper function for SC, which replicates display behaviour of IMAGESC.

20 Aug 2010 1.6

Applied update to real2rgb

14 Dec 2012 1.7

Added disparity, disco and whed colormaps, and updated imsc to behave more like imagesc.

22 Apr 2014 1.9

Replace acknowledgements

18 Aug 2015 1.8

Switch to GitHub repository

16 Feb 2017 1.10

Imdisp now supports movies! Try:
imdisp(imstream('xylophone.mp4'), 'Size', 1)

Contact us