MATLAB: Giving a frame to a image

frameImage Processing Toolbox

How to make a function which frames a image with input as image, frame size and frame color. Where frame colour is a vector of 3 numbers from 0 to 1. The proportion of frame width should be taken from smaller two dimensions of image.

Best Answer

Try something like this
im = imread('pears.png');
im = im2double(im);
frame_size = 100;
frame_color = [1, 0, 1];
framed_image = frameImage(im, frame_color, frame_size);
imshow(framed_image);
function im_out = frameImage(im, frame_color, frame_size)
im_out = repmat(reshape(frame_color, 1, 1, []), ...
size(im, [1 2])+2*frame_size);
im_out(frame_size+1:end-frame_size, frame_size+1:end-frame_size, :) = im;
end
Related Question