How can I put margins in an image?

前端 未结 4 1014
余生分开走
余生分开走 2020-12-11 22:39

I have a binary image of 18x18 pixels and I want to put margins around this image with the purpose of obtaining an image 20x20 pixels.

The image is binary and

4条回答
  •  一个人的身影
    2020-12-11 22:52

    Let's get hackish:

    %// Data:
    A = magic(3);                 %// example original image (matrix)
    N = 1;                        %// margin size
    
    %// Add margins:
    A(end+N, end+N) = 0;          %// "missing" values are implicitly filled with 0
    A = A(end:-1:1, end:-1:1);    %// now flip the image up-down and left-right ...
    A(end+N, end+N) = 0;          %// ... do the same for the other half ...
    A = A(end:-1:1, end:-1:1);    %// ... and flip back
    

提交回复
热议问题