How to create a rectangular mask at known angles?

I created a synthetic image consisting of a circle in the center of the 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 line size / col: 1 by imageSizeX) through the image from top to bottom and at known angles with the edges of the circle (see the attached figure). Also, how can I make the rectangle thicker than 1 on imageSizeX ?. As another option, I would like to try to stop the rectangle in column 350. Finally, any ideas how I can improve the resolution? I mean, is it possible to keep the image size the same when increasing / decreasing the resolution.

enter image description here

I have no idea how to do this. Please, I need help / advice / suggestions that I can get. Many thanks!

0
source share
1 answer

You can use the cos function to find the x coordinate with the correct angle phi . First of all, we note that the angle between the radius that intersects the vertex phi has an angle with x-axis defined by the expression:

theta = pi-phi

and the x coordinate of this vertex is given by

enter image description here

therefore, the mask just needs to set this line 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 this: circle diagram with a rectangular strip

Please note that the max function is used to consider the case when the thickness of the bar will extend beyond the top of the image.

Regarding resolution, image resolution is determined by the size of the matrix being created. In your example, this is (400,300). If you want a higher resolution just increase these numbers. However, if you want to associate a resolution with a higher DPI (dots per inch) so that there are more pixels on each physical inch, you can use the Export Settings window on the File menu.

Shown here: Screenshot of Export Setup dialog

0
source

Source: https://habr.com/ru/post/1215993/


All Articles