在 Matlab 中使用轴坐标生成图像而不绘制它
我有一张充满椭圆形物体的图像。我需要为每个对象设计一个最适合对象本身的椭圆。我找到了一个代码,可以帮助我在图像上绘制椭圆 这里。
我更改了最后部分,将 x
和 y
保存在 3D 矩阵中(一个维度用于 x
,另一个维度用于 y
code>,第三个表示对象的数量)。因为此代码位于 for
循环中,所以我不想在其顶部生成图形省略号,请保存它并使用 imread
上传以将其传递给其余部分的代码。
有没有办法将这个 3D 矩阵转换为黑白图像,其中在图像中的正确位置充满了拟合椭圆?
I have an image full of objects of the shape of an ellipse. I need to design an ellipse for each object that is the best fit for the object itself. I have found a code that helps me to plot the ellipses on the image here.
I have changed the final part saving x
and y
in a 3D matrix (one dimension for x
, the other for y
, and the 3rd for the number of objects). Because this code is in a for
loop, I do not want to generate the figure plot ellipses on top of it, save it and upload with imread
to pass it to the rest of the code.
Is there a way to convert this 3D matrix in a bw image full of the fitting ellipses in the correct position in the image?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于使用
imshow
显示图像后的hold on
语句,因此在现有图形的顶部绘制了椭圆。因此,而不是这样:只需使用
figure
语句创建一个新图形:[Edit]
好的,首先,仅存储
(x, y)< /code> 只给你椭圆中心。要绘制椭圆,您还需要存储其长轴/短轴尺寸(
a
、b
)及其方向角(theta
) 。我会简单地重用您已有的循环,但将每个坐标的黑白图像像素设置为 1 来替换
plot
:现在,有一半在图像边界之外的椭圆。这就是为什么它们的 x,y 坐标需要限制为 (1:256);否则你会得到超出范围的错误。您仍然需要重新考虑是否应该完全删除这些省略号,或者像这里那样部分绘制。
Ellipses are drawn on top of the existing figure because of the
hold on
statement after the image is shown usingimshow
. So, instead of this:Simply create a new figure using the
figure
statement:[Edit]
Ok, first of all, storing only
(x, y)
gives you ellipse centers only. To draw an ellipse, you will also need to store its majos/minor axis size (a
,b
) and its orientation angle (theta
).I would simply reuse the loop that you already have, but replace
plot
with simply setting a bw image pixel to 1 for each coordinate:Right now, there are ellipses which are half outside the image boundaries. That's why their x,y coordinates need to be limited to (1:256); otherwise you get an out-of-range error. You still need to rethink whether these ellipses should be removed entirely, or drawn partially as done here.