필터 지우기
필터 지우기

Intensity of each pixel frawn on an image

조회 수: 3 (최근 30일)
U B
U B 2021년 12월 6일
댓글: U B 2021년 12월 6일
I want to find out the intensity of every pixel if i draw a line on one image.
Im using the below code for drawing a line. Initial valu of (xi,yi) = (353,216) and the final value is (xf,yf) = (553,216).
I = imread('figure63.png');
figure, imshow(I)
hold on
p1 = [353,216];
p2 = [553,216];
plot([p1(1),p2(1)],[p1(2),p2(2)],'Color','m','LineWidth',1)
If I want intensity of every pixel of this line as a column matrix, how do I use imaprofile or I need to use something else?

채택된 답변

KSSV
KSSV 2021년 12월 6일
편집: KSSV 2021년 12월 6일
Read about interp2. You can use interp2 for this.
I = imread('figure63.png');
[m,n,p] = size(I) ;
[X,Y] = meshgrid(1:n,1:m) ;
% Line points
p1 = [353,216];
p2 = [553,216];
% Form a line using polyfit
p = polyfit([p1(1);p2(1)],[p1(2);p2(2)],1) ;
x = linspace(p1(1),p2(1)) ;
y = polyval(p,x) ;
%
iwant = zeros(length(x),p) ;
% Assuming image to RGB
for i = 1:p
iwant(:,i) = interp2(X,Y,I(:,:,i),x,y)
end
end
figure, imshow(I)
hold on
plot(x,y,'Color','m','LineWidth',1)
  댓글 수: 3
KSSV
KSSV 2021년 12월 6일
It is problem with inputs to polyfit, you need to input like shown:
p = polyfit([p1(1);p2(1)],[p1(2);p2(2)],1) ;
Edited the code too.
U B
U B 2021년 12월 6일
got it.

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

추가 답변 (1개)

Walter Roberson
Walter Roberson 2021년 12월 6일
I(p1(2), p1(1):p2(1))
except you should use min and max to ensure that you get increasing order for the column numbers.
This depends on the y coordinates being the same and being integers, a horizontal line. You could use similar logic for a vertical line.
If you need a slanted line then you need improfile or go directly for interp2 which is what improfile uses internally.
  댓글 수: 1
U B
U B 2021년 12월 6일
Yes. This one works. Thank you so much.

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

카테고리

Help CenterFile Exchange에서 Geometric Transformation and Image Registration에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by