To change values in a matrix between two elements
Mostra commenti meno recenti
I have a matrix of zeros 768*1024, considering 4 points (50,100) (450,100) (200,600) and (300,600) i change the values between them and create two lines when i show the image.
i want to change all the points between these two lines to 1's so that i achieve what looks like a white trapezoid in the black background image. Also, this should overwite the previous 0's to 1's in the matrix
code is as follows:
M=zeros(768,1024);
p1=[50,100];
p2=[200,600];
x_value=[50, 200];
y_value=[100, 600];
X=[x_value(1):x_value(2)];
Y=round(interp1(x_value,y_value,X));
i_max=size(Y);
for i=1:i_max(2)
M(Y(i),X(i))=255;
end
p4=[300,600];
p3=[450,100];
a_value=[450,300];
b_value=[100,600];
A = [a_value(2):a_value(1)];
B = round(spline(a_value,b_value,A));
j_max=size(B);
for i=1:j_max(2)
M(B(i),A(i))=255;
end
imshow(M);

1 Commento
Jan
il 2 Lug 2019
You forgot to ask a question. What is the problem?
Risposte (1)
Shashwat Bajpai
il 16 Lug 2019
Hi,
I understand that you are trying to fill the trapezoid created by the points (50,100) (450,100) (200,600) and (300,600).
Please refer to the following code to see if this is what you desire:
xf=[X' A'];
num_el=numel(xf);
yf=[Y' B'];
for i=1:num_el/2
M(yf(i):yf(end-i),xf(i):xf(end-i))=255;
end
imshow(M)
The following link provides a good understanding of how to index into matrices and modify their values:
Categorie
Scopri di più su Resizing and Reshaping Matrices in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!