How to Read or access diagonal pixels of an Image from (R1,C1) to (R2,C2)?

2 Ansichten (letzte 30 Tage)
AMAR P
AMAR P am 19 Sep. 2018
Kommentiert: Saurabh Patel am 21 Sep. 2018
Following is the image am working on. * it's more of splitting an image in sort-of-45degree.* I have taken a random samples along ROW and COLUMNS.
SelectRowSample = 1 112 223 334 445 555
SelectColSample = 1 141 281 421 561 700
  • 1st Blue line start from (141,1) and should end on (1,112).
  • 2nd from (281,1) and should end on (1,223).and onwards.
ImageSize = 555x700
what I have tried?
for ColNum = 1:AllSampleCols
RowElem = 1;
for ColElem = SelectColSample(ColNum):-1:1
text(ColElem,RowElem,'.','Color','b');
if (RowElem < SelectRowSample(ColNum))
RowElem = RowElem + 1;
end
end
end
  1 Kommentar
AMAR P
AMAR P am 21 Sep. 2018
Answer/Solution:
  • Get Co-Ords of the Points that you wish to join.
  • Calculate length of a every line segment.
  • Calculate absolute Co-Ords of the each pixel using linspace.
  • Use X and y Co-ords to draw Plot.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Saurabh Patel
Saurabh Patel am 20 Sep. 2018
Try the following:
% Specify the value of (r1,c1) and (r2,c2)
r1 = 1; c1 = 112;
r2 = 141; c2 = 1;
% alpha is parameter used to reach from point 1 to point 2
alpha = (0:0.1:1)';
% (r,c) are the points on the line
r = round(r1+alpha*(r2-r1));
c = round(c1+alpha*(c2-c1));
% extracting the image intensity at (r,c)
index = sub2ind(size(I),r,c);
selectedI = I(index);
% Check if this is what you desire
figure(), hold on
imagesc(I)
plot(c,r)
  2 Kommentare
AMAR P
AMAR P am 21 Sep. 2018
I think this can work. Will give it a try. What do you think about using.
linspace()
instead of
r = round(r1+alpha*(r2-r1));
c = round(c1+alpha*(c2-c1));
Saurabh Patel
Saurabh Patel am 21 Sep. 2018
Yes, you can use linspace(). It essentially does the same. The reason I used parametric form is to keep it clear that we are getting the image coordinates of the pixels lying on the line (the r and c expressed here as typical parametric form of a line).

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Images finden Sie in Help Center und File Exchange

Produkte


Version

R2015b

Community Treasure Hunt

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

Start Hunting!

Translated by