如何在图像中放置边距? [英] How can I put margins in an image?
本文介绍了如何在图像中放置边距?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一张 18x18 像素的二进制图像,我想在该图像周围放置边距以获得 20x20 像素的图像.
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.
图像是二进制的,可以用1和0的矩阵表示.0 像素为黑色,1 像素为白色.我需要在我拥有的图像周围放置 1 个像素的零边距.
The image is binary and it can be represented by a matrix of 1s and 0s. The 0 pixels are in black colour and the 1 pixels are in white colour. I need to put margins of 1 pixel of zeros around the image that I have.
我该怎么做?
推荐答案
让我们来点 hackish:
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
这篇关于如何在图像中放置边距?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文