"I need to create a figure of the vietnamese flag"
I used this question as an excuse to play around with some of the image processing tools so I thought I'd share the idea of getting the star coordinates from the Vietnamese flag itself. I'd be happy to hear improvements to this method from anyone more familiar with these tools.
I downloaded the attached png image of the Vietnamese flag, read it into Matlab, computed the coordinates of the star edge, then scaled it to a normalized [-1,1] scale. You can use those coordinates to place the star anywhere on a new figure and the dimensions correspond to the actual flag.
Read the image into Matlab
[I, cm] = imread('VietnamFlag.png');
imshow(I, cm)
You could actually stop here if you wanted.
Convert to binary (black & white)
BW = im2bw(I,cm);
imshow(BW)
Get the boundaries of the white object
B = bwboundaries(BW);
B = B{1};
Confirm that the bondary coordinates make sense
hold on
plot(B(:,2),B(:,1),'r-','LineWidth',2)
axis on
Normalize the coordinates to [-1,1]
Bnorm = ((B - min(B,[],1)) ./ (range(B(:,2))./2)) - 1;
Bnorm = fliplr(Bnorm);
Bnorm(:,2) = -1 * Bnorm(:,2);
Plot the star on a new figure
figure()
plot(Bnorm(:,1), Bnorm(:,2), 'k-')
axis equal
axis tight
hold on
plot(0,0,'r+')
Change the center point and scale the size of the star
I'll skip the screen shots and let the curious viewers play around with this.
figure()
plot(Bnorm(:,1)+2, Bnorm(:,2)+3, 'k-')
hold on
plot(2,3,'r+')
axis equal
axis tight
plot(Bnorm(:,1)*5 +2, Bnorm(:,2)*5 +3, 'k-')
hold on
plot(2,3,'r+')
axis equal
axis tight
Create a patch from the star coordinates and fill it will yellow. Plot it against a red axis.
Of course you can use an eyedropper color tool to get the real red and yellow colors from the flag image.
figure()
axes('color', 'r')
h = patch(Bnorm(:,1),Bnorm(:,2),[1 1 0],'EdgeColor', 'none');
axis equal
xlim([-3,3])
ylim([-2,2])