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

조회 수: 1 (최근 30일)
AMAR P
AMAR P 2018년 9월 19일
댓글: Saurabh Patel 2018년 9월 21일
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
AMAR P
AMAR P 2018년 9월 21일
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.

댓글을 달려면 로그인하십시오.

답변 (1개)

Saurabh Patel
Saurabh Patel 2018년 9월 20일
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
AMAR P
AMAR P 2018년 9월 21일
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 2018년 9월 21일
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).

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Read, Write, and Modify Image에 대해 자세히 알아보기

제품


릴리스

R2015b

Community Treasure Hunt

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

Start Hunting!

Translated by