File Exchange

image thumbnail

Image overlay

version 1.2.0.1 (2.09 KB) by

Overlay a binary mask onto an image using a specified color

4.34286
35 Ratings

121 Downloads

Updated

View License

The function IMOVERLAY creates a mask-based image overlay. It takes input image and a binary mask, and it produces an output image whose masked pixels have been replaced by a specified color.

Comments and Ratings (49)

Steve Eddins

Steve Eddins (view profile)

Gabriel-Jonathan, do you mean you want the output to be uint16? Then modify the code inside the function to call im2uint16 instead of im2uint8.

Everything runs smoothly and well. However is there a way to make this work on a 16 bit image?

bourr houssam

ujjwal baid

How to make it work for 16 bit image. I am working on 16 bit medical image.

Easy to understand and use. Works as expected. Thanks Steve!

Awesome... Thanks Eddins.. It helped me a lot... It Works so well now...
 

Steve Eddins

Steve Eddins (view profile)

Shajahan - this imoverlay.m has fewer than 134 lines in it, and it does not call imagesc. You must be using somebody else's imoverlay.m.

Sorry. It does not work for me. Can anyone help me how to make it work?

I am trying to use your same image and same code as you showed in the cell segmentation demo. I am getting following errors.

Error using image
Incorrect number of arguments.

Error in imagesc (line 39)
    hh = image(varargin{:},'CDataMapping','scaled');

Error in imoverlay (line 134)
hF = imagesc(F,climF);

Error in celltry (line 12)
overlay1 = imoverlay(I_eq, bw4_perim, [.3 1 .3]);

Awesome!

emrah

emrah (view profile)

Kirtan

Kirtan (view profile)

Thanks!

It was great. Keep up the good work. Thumbs up.

Massimo Ciacci

Massimo Ciacci (view profile)

Steve Eddins

Steve Eddins (view profile)

Image Analyst, thanks for your comments. I like your suggestion about accepting the output of bwboundaries as the 2nd input argument. I don't really understand your comment about bwperim, though.

Image Analyst

Image Analyst (view profile)

bwperim is not the only way to create outlines. It would be nice if imoverlay were smart enough to see if the input was a binary image, or a cell array that is the output of bwboundaries. A lot of times we threshold and then call bwboundaries. It would be a nice enhancement if it could take the output of bwboundaries as the location of the outlines to draw.

Steve Eddins

Steve Eddins (view profile)

Andrew, you'll have to either pad or resize one of the images to match the other size to overlay them using this function. You could also consider using MATLAB graphics transparency features to overlay one image on another.

Andrew

Andrew (view profile)

Very good tool. Is there any way you can overlay two images that are different sized without one of them becoming dis-formed?

Felix

Felix (view profile)

I'd like to use this function visualize the clipped pixels (e.g. with value 256 in 8bit grayscale) in red, in the preview of a camera recording.

its possible to apply an arbitrary function to each video frame before its displayed in the preview with this:
setappdata(videoHandle,'UpdatePreviewWindowFcn',@some_function);

however, I havent been able to combine this with imoverlay. Any suggestions??

Margarita

Arash

Arash (view profile)

Sid

Sid (view profile)

supriya

Steve Eddins

Steve Eddins (view profile)

Lasse - thanks, I have uploaded a new version based on your suggestion.

Lasse

Lasse (view profile)

This might help to some people

out_red(logical(mask)) = color_uint8(1);
out_green(logical(mask)) = color_uint8(2);
out_blue(logical(mask)) = color_uint8(3);

Hope it helps..

I am not able to implement it. How should I use this function in my program?

Mahmut

Mahmut (view profile)

Mich

Mich (view profile)

Mangesh

Mangesh

is it i can find the upper and lower pixel value of my region..............

TIAN ZHOU

thanks. used in my code. will upload soon

James

James (view profile)

hima

hima (view profile)

This code was great.heyy i want the canny edge borders to be black.now they are in green colour.how to get that???

Rotem

Rotem (view profile)

Great work! saved me some precious time...

paddy84

This is an excellent bit of code. It worked perfectly fine in my case.

Waleed El-Badry

that's an excellent piece of code.

Carlos Adrián Vargas Aguilera

Great tool. Now I can paint NaN's in black on imagesc.

Thanks

Robert Misevski

Great tool work very well for what a needed to do.

Steve Eddins

Matt - I added a note and an example to the documentation based on your suggestion. Thanks!

Phillip SUn

great and loved it

B r

Matt Whitaker

Simple, useful and well styled and coded. Did something in my existing code similar but this is a bit faster and less memory. Steve, you might want to note in the documentation that if you have a double input outside the range of 0-1 (soemthing you typically use imagesc to display) that you would want to run mat2gray on it before passing to this function. A useful further enhancement would be either to auto detect and apply this or have an optional switch.

Chai Tan

Works great. Saves me a few lines of code! :) Thanks.

Lennart Burg

I think it works great. Thnx

Gil Hornung

I would like to overlay a picture which is not bw.

James Jones

??? Subscript indices must either be real positive integers or logicals.

Error in ==> imoverlay at 54
out_red(mask) = color_uint8(1);

Updates

1.2.0.1

Updated license

1.2

Based on a suggestion from Lasse, I added code to automatically convert the mask input to be logical.

MATLAB Release
MATLAB 7.2 (R2006a)

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

» Watch video