Interactive pixel extraction from an image along custom line
28 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Florian
el 6 de Jun. de 2020
Comentada: Z.S.
el 2 de Jul. de 2021
The following code extracts pixel values for the first column of an image.
IMt = imread('test.jpg');
% convert to double format
IMtd=double(IMt);
% isolate first trace
trace=(IMtd(:,1));
What I need to do instead is extract the pixel values along an arbitrary line (see red lines in below image). In other words, along a direction which is diagonal to rows and columns.
Is there a tool in Matlab available where one can plot an image and then interactively draw a line along which the values will be extracted?
If I use...
imshow(IMt)
datacursormode on
...the pixel values are interactively displayed when I hove over the image. There just needs to be a way to write them into an array at the same time.
0 comentarios
Respuesta aceptada
Image Analyst
el 6 de Jun. de 2020
Try improfile()
or drawline() with a callback function
5 comentarios
Image Analyst
el 7 de Jun. de 2020
You never know before you draw the line but once you draw it, you know, and that's what I computed and passed in.
You can rate it one star in the help and it will bring up a form that you can put your comment.
Z.S.
el 2 de Jul. de 2021
I think the variables linestart and lineend are miss-positioning the x and y coordinates of the end points for using improfile. According to the help page of improfile, the format should be improfile(I,x,y). Then the code should be something like:
I = imread('liftingbody.png');
imshow(I);
roi = drawline('Color','r');
% now draw line interactively
%
% Read out the X and Y coordinates of the start and end points
line_xs = [roi.Position(1,1), roi.Position(2,1)]
line_ys = [roi.Position(1,2), roi.Position(2,2)];
% extract pixel values along line
pixvals = improfile(I,line_xs,line_ys);
figure
plot(pixvals,1:length(pixvals),'k'), axis tight, title('pixel values')
xlabel('pixel greyscale values')
ylabel('relative position from linestart (0) to lineend')
Más respuestas (1)
Julianna Mather
el 8 de Jun. de 2020
I've been thinking about how to frame the enhancement request for the functionality you requested, and I have some questions.
I'm curious to know what your ultimate goal is and what exactly you want to happen along the diagonals.
Suppose you have a diagonal line that crosses through a pixel just a tiny, tiny bit, should it get counted? Or perhaps it would be appropriate to determine the number of rows and columns the diagnol spans and then use hypot to figure out the number of pixels to sample uniformly along the line. (You can do that right now with improfile now, of course, for non-interactive syntaxes.)
So all of this gets me to the first question: What is your ultimate goal of having improfile return more pixel sites? How will you use that increased resolution?
(BTW, I'm not critiquing your request, I just want to make sure that we get a solution that will satisfy your use case.)
1 comentario
Ver también
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!