Info

This question is closed. Reopen it to edit or answer.

I would appreciate some assistance on some coding.

1 view (last 30 days)
Arslan Ahmed
Arslan Ahmed on 22 Nov 2019
Closed: MATLAB Answer Bot on 20 Aug 2021
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 Comments
Steven Lord
Steven Lord on 22 Nov 2019
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 on 22 Nov 2019
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

Answers (1)

Image Analyst
Image Analyst on 22 Nov 2019
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 Comments
Arslan Ahmed
Arslan Ahmed on 23 Nov 2019
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 on 23 Nov 2019
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.

Tags

Community Treasure Hunt

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

Start Hunting!