Clear Filters
Clear Filters

Help using rectangle() function to generate a matrix for image processing;

6 views (last 30 days)
Hi y'all i have a question about the function rectangle(), im using it to make 6x4 disk grid.
I was trying to use viscircles() as it would be much easier, but i cant fill them in appropiately.
Im using it to generate circles, but for the life of me I can not figure out how to save the figure output.
My code currently reads:
for i=1:24
h=rectangle('Position', [px(i) py(i) d d],'Curvature',[1,1],'FaceColor',[0 0 (1/24)*i]);
Where px and py are the specific positions where i want the disks printed, and d is the diameter of those disks.
These were read from imfindcircles(), giving me specific points that each circle is from.
Each one needs to be a different value (preferably 1:24). a circle of 1's then 2's and so on an so forth.
this is what im getting, which is exaclty what i need. But i have no way of saving it as data.
I have an idea to try the insertshape() command, but it seems like i couldnt save it as a [0 255] value instead of a color.
If you have any ideas or suggestions please reach out.

Accepted Answer

Kritika Bansal
Kritika Bansal on 19 Aug 2019
To save the figure generated by the code provided by you, you can use the savefig function as follows:
If you wish to save the data (attributes of each rectangle) of the figure, you can create a structure and log the data into it with every iteration.
%dummy arrays
rect_data = struct;
for i=1:6
pos = [px(i) py(i) d d];
cur = [1,1];
fcolor = [0 0 (1/24)*i];
rect_data(i).position = pos;
rect_data(i).cur = cur;
rect_data(i).fcolor = fcolor;
h=rectangle('Position', pos,'Curvature',cur,'FaceColor',fcolor);

More Answers (0)

Community Treasure Hunt

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

Start Hunting!