How to draw a white border around an image(or a group of images in a folder)

5 次查看(过去 30 天)

I have an image :-

Now i want to draw a white border around the image,such that i get this:-

How can i do this.Please help.

回答(1 个)

Image Analyst
Image Analyst 2017-4-1
Use padarray():
padsize = 1;
padvalue = 255; % or 1 if image is single, double, or logical.
paddedImage = padarray(originalImage, padsize, padval);
  3 个评论
Image Analyst
Image Analyst 2017-4-1
Then just write it in yourself
grayImage(:, 1) = 255; % Make left column white.
grayImage(:, end) = 255; % Make right column white.
grayImage(1, :) = 255; % Make top row white.
grayImage(end, :) = 255; % Make bottom row white.
Kumar Arindam Singh
编辑:Kumar Arindam Singh 2017-4-4
I have this code: %read image im=imread('2.jpg'); figure,imshow(im); %convert image to grayscale components imr=im(:,:,1); img=im(:,:,2); imb=im(:,:,3);
%write the images to specified folders with a suitable name imwrite(imr, 'C:\Users\hp\Documents\MATLAB\Imageprocessing\project1\001r.jpg','jpg'); imwrite(img, 'C:\Users\hp\Documents\MATLAB\Imageprocessing\project1\001g.jpg','jpg'); imwrite(imb, 'C:\Users\hp\Documents\MATLAB\Imageprocessing\project1\001b.jpg','jpg');
%calculate the level of the blue image using OTSU's threshold function level = graythresh(imb);
%converting the blue component grayscale image to binary image with the %help of level calculated using OTSU's threshold function bwb=im2bw(imb,level);
%show the binary image figure,imshow(bwb);
%save the binary image imwrite(bwb, 'C:\Users\hp\Documents\MATLAB\Imageprocessing\project1\001bin.jpg','jpg'); %tried implementing your code snippet bwb(:,1)=255; bwb(:,end)=255; bwb(1,:)=255; bwb(end,:)=255; figure,imshow(bwb);
There seems to be no effect. I am using MATLAB R2015a

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Image Processing Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by