File Exchange

image thumbnail

SC - powerful image rendering

version 1.10 (72.3 KB) by

Useful tool for rendering and outputting information rich images

4.72222
41 Ratings

49 Downloads

Updated

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.

Comments and Ratings (77)

Andrew Ward

Andrew Ward

Andrew Ward

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?

S

S (view profile)

Emma Stewart

Pearl

Pearl (view profile)

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 ?

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.

Oliver Woodford

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

as hz

as hz (view profile)

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

Jon

Jon (view profile)

That's perfect - thanks, Oliver!

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));

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,
Jon

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.

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
Amirali

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
Amirali

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.

cheers

Matteo Niccoli

Why only 1 star?

Oliver Woodford

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

ClaudiaParise

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.

Thanks,

Claudia

TJ

TJ (view profile)

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')

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`): http://www.robots.ox.ac.uk/~ojw/software.htm
Thank you!

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);

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);
pause(0.1);

Best regards
Abbas

Julia

Julia (view profile)

Terrific

SHAFIQUL

bella

bella (view profile)

Tao Han

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.

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?

SSY

SSY (view profile)

Nice one!!

Fabian

Fabian (view profile)

Rafa

Rafa (view profile)

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

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.

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.

Harald Mayr

Qianqian

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

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. :)

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]);
sc(peaks(128));

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

Oliver Woodford

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

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?

Oliver Woodford

Camille: I think it's unlikely.

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...)

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).

Dove

Dove (view profile)

Hi Oliver,

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

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.

Hi! Is that possible to fix dateticks on this kind of image? I would need to apply dynamic date ticks (see http://www.mathworks.com/matlabcentral/fileexchange/27075-intelligent-dynamic-date-ticks, wich works on plot, but apparently not on imagesc and sc...
Thanks for reply!
Camille.

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.

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?

Thanks

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.

Oliver Woodford

Camille:
axis on

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 :-)

Alize

Alize (view profile)

K E

K E (view profile)

Helpful, thanks

Ange

Ange (view profile)

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.

Justin

Justin (view profile)

The autopreservation of aspect ratio (mentioned by http://www.mathworks.com/matlabcentral/fileexchange/authors/27420) 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.

Jun wan

veri nice .bue i didn't try it

Idillus

Nice

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!

Oliver Woodford

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

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'));

C. Chaya

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

C. Chaya

Doesn't show subplot titles. Must use

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

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.

M HEMA NITHYA

Ernesto Moya

It's great.

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!

Felix Hebeler

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

p p

best viewing code ever

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.

Updates

1.10

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

1.8

Switch to GitHub repository

1.7

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

1.6

Applied update to real2rgb

1.5

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

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).

1.3

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

1.2

Fixed typo in the description!

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.

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

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

Added 'stereo_col'. Changed text a bit.

Fixed saturation issue with 'prob_jet'

Bug fix to 'stereo'

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

Bug fix to 'prob_jet' colormap.

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

Updates seem to be revision behind.

Reduced cyclic number of code.

Fixed resize issue

Faster image display, numerous other improvements

Improvements and a bug fix to the function

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

MATLAB Release
MATLAB 7.0.1 (R14SP1)

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

» Watch video