MATLAB: How to add box to an image

box around imageframeImage Processing Toolboximshowrectangle

I have two images ('yellow.png' and 'bird.png'). See below.
1-4.png bird1_before.jpg
How can I make a box AROUND the image borders with self-defined box colours, say all four lines with grey colour [0.5 0.5 0.5]?
See below.
1-1.png 1-2.png
Please can you help?

Best Answer

If the bad lines are always the rightmost one and the bottom one, you can simply crop the image to not include those:
rgbImage = rgbImage(1:end-1, 1:end-1, :);
To pad the image with certain color, you can use padarray() on each color channel. There are other ways. Let me know if it's still a problem for you.