Info

此问题已关闭。 请重新打开它进行编辑或回答。

I would appreciate some assistance on some coding.

1 次查看(过去 30 天)
The goal is to create this image:
It is a 2-dimensional array made of ones (size 100x100), and I need to set up a single 'for' loop with 100 iterations from row 1 to row 100, applying conditional statements inside the loop to generate the binary image.
There may be various ways to go by achieving my goal, the path I have chosen consists of me gathering all the points, and thus filling in the points.
Image below to show my progress:
So this led me to think of two questions. 1) Is it even possible for me to "fill" the points, and 2) Is there a better way to do this, and if so, could anyone supply me with the neccesary coding required?
Thanks. (p.s, this is being done on R2019A, but R2019B works just fine too)
  2 个评论
Steven Lord
Steven Lord 2019-11-22
Can you show us the code you've written to try to solve the problem and describe the specific difficulty or difficulties you're having? If you do we may be able to provide some guidance and/or feedback on your code.
Arslan Ahmed
Arslan Ahmed 2019-11-22
I am very new to Matlab, and so you may notice my attempts were cut short and I soon ran into difficulties.
The code currently is as follows:
Screenshot_164.png
I have attempted to use this, but I am not so sure how this would work in creating the various shapes in different positions, or how to utilise this code to answer my problems.
for j = 1:100
A(j,j:100) = 1;
end

回答(1 个)

Image Analyst
Image Analyst 2019-11-22
If you have the vertex points, create the binary image
binaryImage = false(100, 100);
Then use poly2mask(x, y, 100, 100) to create binary images that you OR in with the first one.
oneRegion = poly2mask(x, y, 100, 100);
binaryImage = binaryImage | oneRegion;
Repeat for every closed square or triangular region using the x and y coordinates of that particular region.
  6 个评论
Arslan Ahmed
Arslan Ahmed 2019-11-23
I can attempt both, the tedious method aswell as using built-in functions. How would I go about doing it the tedious method? Is there some example coding you could potentially assist me with?
Image Analyst
Image Analyst 2019-11-23
Nothing that I have that is all ready to go and ready to hand over to you. I'd have to go through the same tedious exercise as you would, so I'll just leave that to you.

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by