Let's say my image is img=zeros(100,100,3)
, my outputs are several ellipse which i get using a created function [ret]=draw_ellipse(x,y,a,b,angle,color,img)
, I can display one ellipse using imshow(ret)
.For the moment, I'm trying to show serval ellipse in the image. But i don't know how to code it. will ‘for loop’ work or I need to hold them?
Asked
Active
Viewed 176 times
1
3 Answers
2
If this is related to what you were doing in your previous question, then what you need to do is to pass the result of one iteration as input to the next.
So assuming that the function [ret]=draw_ellipse(x,y,a,b,angle,color,img)
you mentioned takes as input an image img
and returns the same image with an ellipse drawn on it, you could do this:
%# ellipses parameters
%#x = {..}; y = {..};
%#a = {..}; b = {..};
%#angle = {..}; color = {..};
img = zeros(200,100,'uint8'); %# image to start with
for i=1:10
img = draw_ellipse(x{i},y{i}, a{i},b{i}, angle{i}, color{i}, img);
end
imshow(img)
-
Thanks a lot!Amro,your answer is exactly what i want. You helped me so much along the way. – Elsie Oct 16 '11 at 10:33
-
If i want to set a random series value of the center point coordinates of ellipse, assume'x=rand(1,10)*100' and 'y=rand(1,10)*100', how can i put them into '{}'? I'm short of the knowledge on the difference between '{}' and '[]'. – Elsie Oct 17 '11 at 02:32
-
@Ivy: if you want to access elements of a vector/matrix, use parentheses `x(i)`, for cell arrays use curly brackets `x{i}`. To convert between the two, you can use functions like CELL2MAT, NUM2CELL, MAT2CELL, etc... Make sure to read the documentation for more info. In this case, vectors would work just fine, no need for cell arrays – Amro Oct 17 '11 at 12:52
-
:Hi,Amro. Sorry to bother you again. If i want to draw random ellipses,using random x,y,a,b values, but how can i prevent them overlapping from each other, and then draw them into image. – Elsie Oct 24 '11 at 04:23
-
@Ivy: since you already asked that question separately, I posted my answer on that page: http://stackoverflow.com/questions/7833534/matlab-how-to-avoid-ellipses-overlapping-in-image/7897214#7897214 – Amro Oct 25 '11 at 23:54
0
I'm a bit unsure of what you want. You want to show several ellipse in one image, like plotting several graphs with hold on?
There is no equivalent command for images, but a simple solution is to add the ellipses into one image and show that one:
several_ellipse = ellipse1 + ellipse2 + ellipse3;
imshow(several_ellipse)

Ghaul
- 3,340
- 1
- 19
- 24
0
Presumably you want to pass ret
as the final input to the next call to draw_ellipse
.

Nzbuu
- 5,241
- 1
- 29
- 51