Lines for the region of interest.

1 vue (au cours des 30 derniers jours)
Thulyo Neder
Thulyo Neder le 9 Sep 2020
Modifié(e) : Thulyo Neder le 18 Sep 2020
Lines for ROI.

Réponses (1)

Vinai Datta Thatiparthi
Vinai Datta Thatiparthi le 15 Sep 2020
Hey!
Suppose, the image dimensions are [w h] and the image center is at (p,q) [with general considerations}.
"How do I plot lines in an image according to the angles..."
Using a little bit of trigonometry and MATLAB's column-major notations, the X-coordinate of the third vertex of the shape made by the coordinate axes and the blue line that makes an angle of alpha with the Y-axis would be:
The Y-coordinate would be 1.
Using these coordinates, use the line function to draw the line on the image as follows:
im = imread('img.png');
imshow(im);
hold on;
line([x, p], [y, q]); % Draws a line from (p,q) to (x,y)
For the next line i.e. with angle beta, replace "alpha" in the aforementioned equation with "alpha + beta" angles. You'll probably have to write a code to do this process repeatedly if you want a programmatic solution to this problem.
"extract region between these lines for analysis..."
Use the Polygon functionality.
Region created by vertices (p,q), (p,1) & (x,y) [which we just calculated] can be inputs to this. Examples on this Documentation page describe how to do this non-interactively using images.roi.Polygon.
Similarly, for the line that makes an angle beta, you'd have to add an additional vertex - the edge/corner of the image i.e. [w 1].
Hope this helps!
  1 commentaire
Vinai Datta Thatiparthi
Vinai Datta Thatiparthi le 18 Sep 2020
Hey Thulyo,
Have a look at this code:
close all
%% Setup
im = rgb2gray(imread('peppers.png'));
[heightIm, widthIm] = size(im); %
% Center of the image (p,q)
p = widthIm/2;
q = heightIm/2;
%% Red lines
% Horizontal Red Line
rHorzX1 = 1;
rHorzY1 = q;
rHorzX2 = widthIm;
rHorzY2 = q;
% Vertical Red Line
rVertX1 = p;
rVertY1 = 1;
rVertX2 = p;
rVertY2 = heightIm;
%% Blue Lines
alpha = 15; % In degrees
bX2 = p + q*tan(alpha*pi/180);
bY2 = 1;
beta = 30;
bX3 = p + q*tan((alpha+beta)*pi/180);
bY3 = 1;
%% Display everything
imshow(im);
hold on;
line([rHorzX1,rHorzX2],[rHorzY1,rHorzY2],'Color','r')
line([rVertX1,rVertX2],[rVertY1,rVertY2],'Color','r')
line([p,bX2],[q,bY2],'Color','b')
line([p,bX3],[q,bY3],'Color','b')
%% Extract Region
% Region of Interest
h = images.roi.Polygon(gca,'Position',[p, q; rVertX1, rVertY1; bX2, bY2]);
% Create mask for ROI
maskRegion = createMask(h);
% Create new image
dispImg = im;
% Logical Indexing
dispImg(maskRegion == 0) = 0;
figure
% Display only the ROI image
imshow(dispImg)
Hope this helps!

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by