0

I have created a synthetic image that consists of a circle at the centre of a box with the code below.

%# Create a logical image of a circle with image size specified as follows:
imageSizeY = 400;
imageSizeX = 300;

[ygv, xgv] = meshgrid(1:imageSizeY, 1:imageSizeX);

%# Next create a logical mask for the circle with specified radius and center
centerY = imageSizeY/2;
centerX = imageSizeX/2;
radius  = 100;

Img   = double( (ygv - centerY).^2 + (xgv - centerX).^2 <= radius.^2 );


%# change image labels from double to numeric
for ii = 1:numel(Img)

    if Img(ii) == 0
        Img(ii) = 2;  %change label from 0 to 2
    end

end

%# plot image
RI = imref2d(size(Img),[0 size(Img, 2)],[0 size(Img, 1)]);
figure, imshow(Img, RI, [], 'InitialMagnification','fit');  

Now, i need to create a rectangular mask (with label == 3, and row/col dimensions: 1 by imageSizeX) across the image from top to bottom and at known angles with the edges of the circle (see attached figure). Also, how can i make the rectangle thicker than 1 by imageSizeX?. As another option, I would love to try having the rectangle stop at say column 350. Lastly, any ideas how I can improve on the resolution? I mean is it possible to keep the image size the same while increasing/decreasing the resolution.

enter image description here

I have no idea how to go about this. Please i need any help/advice/suggestions that i can get. Many thanks!.

gary105
  • 49
  • 7
  • 1
    Could you clarify your goal? For some example angle phi, what would be the correct mask that you are looking for? – Teddy Ort Mar 08 '17 at 04:32
  • Thanks @Teddy Ort. I don't quite get your point, but my goal is to obtain several images with varying angle phi values(say 10, 20, 30, 60, 90, 120, 150 degrees). I will then use this to validate results from a completely different method. Please let me know if its clear. – gary105 Mar 08 '17 at 05:38

1 Answers1

0

You can use the cos function to find the x coordinate with the correct angle phi. First notice that the angle between the radius that intersects the vertex of phi has angle with the x-axis given by:

theta=pi-phi

and the x coordinate of that vertex is given by

enter image description here

so the mask simply needs to set that row to 3.

Example:

phi = 45;       % Desired angle in degrees
width = 350;    % Desired width in pixels
height = 50;    % Desired height of bar in pixels
theta = pi-phi*pi/180;    % The radius angle
x = centerX + round(radius*cos(theta)); % Find the nearest row
x0 = max(1, x-height); % Find where to start the bar
Img(x0:x,1:width)=3;

The resulting image looks like: graph of circle with rectangular bar

Note that the max function is used to deal with the case where the bar thickness would extend beyond the top of the image.

Regarding resolution, the image resolution is determined by the size of the matrix you create. In your example that is (400,300). If you want higher resolution simply increase those numbers. However, if you would like to link the resolution to a higher DPI (Dots per Inch) so there are more pixels in each physical inch you can use the "Export Setup" window in the figure File menu.

Shown here: Screenshot of Export Setup dialog

Teddy Ort
  • 756
  • 6
  • 7
  • Thanks @Teddy Ort, It works perfectly. Nonetheless, i was wondering how i can make the rectangle thicker than it is. Secondly, will love to try having the rectangle stop at say column 350. Any suggestions please? Many thanks. – gary105 Mar 08 '17 at 20:42
  • I can add that to the answer. Could you update your question to include this so that the answer is still applicable for others reading? – Teddy Ort Mar 08 '17 at 22:34
  • Oh so sorry, didn't see that you've responded a long time ago. I have updated the question and I added a bit more. Thank you so much! – gary105 Mar 09 '17 at 02:18
  • Thanks @Teddy Ort. This makes sense, but changing the resolution this way would only affect the resolution of the resulting image in the figure window and not the original matrix in the code, isn't it? (Let me know if otherwise). Again, let's use a practical example: what should i do if i want to create this same image at a resolution of 14pixels/diameter of the circle? and then if i as well want to increase this to 28pixels/diameter of the circle? – gary105 Mar 10 '17 at 21:14
  • I think i've got this covered now. I greatly appreciate your help @Teddy Ort – gary105 Mar 18 '17 at 23:46