Giving a frame to a image

7 views (last 30 days)
Mayur Deogade
Mayur Deogade on 5 Sep 2020
Commented: Ameer Hamza on 9 Sep 2020
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.

Accepted Answer

Ameer Hamza
Ameer Hamza on 5 Sep 2020
Edited: Ameer Hamza on 5 Sep 2020
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
  19 Comments
Mayur Deogade
Mayur Deogade on 8 Sep 2020
Thank you so much for your help. It really helped me a lot.
Ameer Hamza
Ameer Hamza on 9 Sep 2020
I am glad to be of help!

Sign in to comment.

More Answers (0)

Categories

Find more on Images in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!