2017-03-08 81 views
0

我想通过首先指定其高度和宽度,然后使用meshgrid函数将图像数字化来创建分辨率为56像素/直径(具有不同直径,例如50,100和150像素)的图像(请参阅下面的示例代码)。其次,我如何将分辨率提高2倍(例如:112和224像素/直径)?如何创建指定分辨率的图像?

例子:

RowSize = 400; 
ColSize = 400; 

[gridRow, gridCol] = meshgrid(1:RowSize, 1:ColSize); 

%specify the diameter 
d = 100; 

% create the image 
I  = (gridRow - 200).^2 + (gridCol - 200).^2 <= (d/2).^2; 
figure, imshow(I, []); 

的主要问题,我会觉得是如何确定Row和Col尺寸,使得我所期望的分辨率。

非常感谢您的任何帮助/建议。谢谢!

回答

0

我想这是你所追求的:

%specify the diameter 
d = 100; 

RowSize = d; 
ColSize = d; 

%Subtract 0.5 to get the center correclty 
[gridRow, gridCol] = meshgrid((1:RowSize)-0.5, (1:ColSize)-0.5); 

% create the image 
I = (gridRow - d/2).^2 + (gridCol - d/2).^2 <= (d/2).^2; 
figure, imshow(I, []); 

结果:
enter image description here

+0

感谢@Rotem。它以这种方式工作,但我实际上想通过指定高度和宽度从头开始创建图像。我已经编辑了相应的问题。请看看。谢谢你的时间!。 – oma11

+0

现在我真的迷了路...'gridRow'和'gridCol'的分辨率是'RowSize×ColSize'。你如何从'gridRow'和'gridCol'创建一个图像? – Rotem

+0

请在此处查看剩余的代码:'centerY = RowSizeY/2; centerX = ColSizeX/2; 直径= 100; Img =(gridRow - centerY)。^ 2 +(gridCol - centerX)。^ 2 <=(diameter/2)。^ 2; figure,imshow(Img,[],'InitialMagnification','fit')'。代码在图像的中心创建一张光盘(没有添加它们,因为我不确定是否需要这些光盘)。请让我知道你的想法。谢谢一堆! – oma11