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

3 ビュー (過去 30 日間)
Sam Freitas
Sam Freitas 2019 年 8 月 13 日
回答済み: Kritika Bansal 2019 年 8 月 19 日
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]);
end
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.
fig_test.png
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.
Thanks

採用された回答

Kritika Bansal
Kritika Bansal 2019 年 8 月 19 日
Hi,
To save the figure generated by the code provided by you, you can use the savefig function as follows:
savefig(<figurename.fig>);
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
px=[1,1,1,2,2,2];
py=[1,2,3,1,2,3];
d=1;
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);
end

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by