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 Center および File ExchangeRead, 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