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

1 次查看(过去 30 天)
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