简体   繁体   English

创建一个二进制图像

[英]Create a Binary Image

I have a question concerning the creation of a binary image in MATLAB. 我有一个关于在MATLAB中创建二进制映像的问题。 I want to create a binary image with 3907x3713 pixels. 我想创建一个3907x3713像素的二进制图像。 Each pixel is represented by a position in a matrix (I presume). 每个像素由矩阵中的位置表示(I假定)。 Each pixel has to be black (so value 0 I guess) except for the pixels between 1000-1500 ( x -axis) and 2000-2500 ( y -axis), these have to be white (value 256 I guess). 除了介于1000-1500x轴)和2000-2500y轴)之间的像素外,每个像素都必须为黑色(所以我猜值为0 ),这些像素必须为白色(我想值为256 )。

First of all I create a matrix with 3907 rows and 3713 columns. 首先,我创建一个具有3907行和3713列的矩阵。 I fill these up with zeros (through the function zeros ). 我用零填充这些(通过功能zeros )。 But than I get stuck to find an easy way to replace some with the value 256 . 但是,比起我想要找到一种简单的方法来替换值256的简单方法,我更加256

Thank you for your time and help. 感谢您的时间和帮助。

zeros function returns an array of double . zeros函数返回一个double数组。

To create a really binary image with only black and white colors, convert your array to logical type: 要创建仅具有黑白颜色的真正二进制图像,请将数组转换为逻辑类型:

im=logical(zeros(3907, 3713));

This will help to use significally (64 times) less memory. 这将有助于显着减少(64倍)的内存使用。

In such image 0 is used for black, 1 is used for white. 在这种图像中,0用于黑色,1用于白色。 No other values are allowed. 不允许其他值。

So, to create some white pixels use 所以,要创建一些白色像素使用

im(1000:1500,2000:2500) = 1;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM