save data in matrix after improfile

조회 수: 4 (최근 30일)
Eva G
Eva G 2021년 10월 4일
답변: Prachi Kulkarni 2021년 10월 18일
Hi,
I have an image and I would like to get a cross section of it- line intensity profile to evaluate the lines if are equally seperated . I had set improfile at the mid-point of the image and I got the intensity profile. After I would like to save the improfile matlab figure into a matrix and try get from the matrix a specific row for all the columns but I cant find the way to do it.
Please see my code below :
I = imread('Test-0.tif'); %% I have tif files but here I uploaded a jpg
x = [0 size(I,2)];
y = [size(I,1)/2 size(I,1)/2]; %choose the middle y data
improfile(I,x,y);
imshow(I);
figure
M=improfile(I,x,y);
save('data.mat','M');
  댓글 수: 3
Eva G
Eva G 2021년 10월 4일
Sorry for the confusion . It was something that I was testing to find the issue . M=improfile (I,x,y) was initial code but it seems that it saves a matrix (2049x1) double and not a 2d matrix as it should.
Geoff Hayes
Geoff Hayes 2021년 10월 4일
@Eva G - are you sure that the output should be sized differently? Maybe you need to capture the x and y coordinates as indicated here.

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

답변 (1개)

Prachi Kulkarni
Prachi Kulkarni 2021년 10월 18일
Hi,
In the code snippet you have provided, the pixel values are sampled along only one line segment in image I. The endpoints of this line segment are I(0, size(I,1)/2) and I(size(I,2), size(I,1)/2). Hence, the output variable M is giving a single vector of pixel values along the segment.
To get the profile along multiple horizontal line segments in the image, you will have to generate the profile for all the line segments in a loop and combine their output in a matrix. For example, to get a profile along 3 horizontal lines at the top, middle and bottom, the code would be as follows.
I = imread('Test-0.jpg'); %% I have tif files but here I uploaded a jpg
x = [0 size(I,2)];
M = [];
for yi = [1 size(I,1)/2 size(I,1)]
y = [yi yi]; %choose the middle y data
figure
Mi = improfile(I,x,y);
M = [M ; Mi'];
end
save('data.mat','M');

카테고리

Help CenterFile Exchange에서 Image Segmentation and Analysis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by