Borrar filtros
Borrar filtros

how to get the movement of an object with respect to time in MATLAB?

4 visualizaciones (últimos 30 días)
Tayyaba Bano
Tayyaba Bano el 22 de Dic. de 2021
Comentada: Tayyaba Bano el 15 de Feb. de 2022
Hi,
I am working with a thing flexible structure, I have got images from experiments. I want to know how I can trace an edge and get its mpvement for example in terms of displacement and velocity verses time?
Image is attached.
Thanks
Tayyaba
  1 comentario
yanqi liu
yanqi liu el 23 de Dic. de 2021
yes,sir,may be upload the image list to detect object and trace the left edge as target

Iniciar sesión para comentar.

Respuestas (1)

Image Analyst
Image Analyst el 22 de Dic. de 2021
Do you have a method to locate the edge already? That would be the first step. Maybe try hough() or houghlines() if you don't have a method yet.
After that you can get the endpoints and centroid locations. Then make an array where you keep track of those 3 locations from frame to frame. Multiply by a spatial calibration factor to get distances in real world units such as millimeters. Velocity is the change in distance divided by the frame time.
  7 comentarios
Tayyaba Bano
Tayyaba Bano el 15 de Feb. de 2022
Thank you very much for your kind and detailed reply.
I tried this with a litle bit change as I get error for 'imnImfilt' image filering and also with xline and yline. The error states:
"Undefined function or variable 'imnImfilt' and 'xline' or 'yline'. "
Also I tried to display the boundaries but unfortunately it did not display that. May be there is an error in the last part of the code.Moreover, the boundary needed is attached, which I have to trace over the images to get its velocity verses time.
The code is as follows:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 15;
markerSize = 40;
%--------------------------------------------------------------------------------------------------------
% READ IN IMAGE
fileName = 'slide1.bmp';
grayImage = imread(fileName);
% Get the dimensions of the image.
% numberOfColorChannels should be = 1 for a gray scale image, and 3 for an RGB color image.
[rows, columns, numberOfColorChannels] = size(grayImage)
if numberOfColorChannels > 1
% It's not really gray scale like we expected - it's color.
% Extract the blue channel (so the magenta lines will be white).
grayImage = grayImage(:, :, 3);
end
%--------------------------------------------------------------------------------------------------------
% Display the image.
subplot(3, 2, 1);
imshow(grayImage, []);
impixelinfo;
axis('on', 'image');
caption = sprintf('Original image is %d rows by %d columns', rows, columns);
title(caption, 'FontSize', fontSize);
hold on
drawnow;
% Crop image
verticalProfile = mean(grayImage, 2);
subplot(3, 2, 2);
plot(verticalProfile, 1:length(verticalProfile), 'b-', 'LineWidth',2);
grid on;
title('Vertical Profile')
axis ij;
thresholdValue = 15;
row1 = find(verticalProfile > thresholdValue, 1, 'first');
row2 = find(verticalProfile > thresholdValue, 1, 'LAst');
grayImage = grayImage(row1:row2, :);
% Get a binary image
thresholdValue = 50;
mask = grayImage > thresholdValue;
mask = bwareafilt(imfill(mask, 'holes'), 1);
% grayImage = adapthisteq(grayImage, "NumTiles",[16, 16]);
% grayImage = medfilt2(grayImage, [27, 7]);
mask = edge(grayImage, "canny");
% Display the image.
subplot(3, 2, 3);
imshow(mask, []);
axis('on', 'image')
impixelinfo
lowThreshold = 17;
highThreshold = 200;
% Get a mask for spots
spots = mask > lowThreshold;
% Get rid of any spots less than 1000 pixels.
spots = bwareafilt(spots, [1, 10000]);
% Erase those spots from the gray scale image.
filteredImage(spots) = 0;
imshow(filteredImage, []);
axis('on', 'image')
impixelinfo
subplot(3, 2, 4);
horizontalProfile = mean(grayImage, 1);
verticalProfile = mean(grayImage, 2);
subplot(3, 2, 4);
plot(verticalProfile, 1:length(verticalProfile), 'b-', 'LineWidth',2);
grid on;
title('Vertical Profile')
axis ij;
subplot(3, 2, 5);
plot(horizontalProfile, 'b-', 'LineWidth',2);
grid on;
title('Horizontal Profile')
xlim([1, length(horizontalProfile)])
%display the boundaries
boundaries = bwboundaries(filteredImage);
subplot(3, 2, 4);
imshow(grayImage);
hold on;
boundaries = bwboundaries (mask);
numberOfBoundaries = size(boundaries,1);
title('Image With Boundaries')
Tayyaba Bano
Tayyaba Bano el 15 de Feb. de 2022
I tried some other way.But I am not getting the right boundary and also red spots.
Could you please suggest how to get rid of those spots? when I use the image filtering option and the mask for spots, as you suggested earlier. Unfortunately it gives me errors.
Thanks
grayImage = imread('slide1.bmp');
[rows, columns, numberOfColorChannels] = size(grayImage);
if numberOfColorChannels > 1
grayImage = rgb2gray(grayImage);
end
% Crop image
thresholdValue = 15;
row1 = find(verticalProfile > thresholdValue, 1, 'first');
row2 = find(verticalProfile > thresholdValue, 1, 'LAst');
grayImage = grayImage(row1:row2, :);
% Display the image.
subplot (3,2,1);
imshow(grayImage);
impixelinfo;
title('Original Image')
%--------------------------------------------------------------------------------------------------------
% SEGMENTATION OF IMAGE
% Get a binary image
mask = grayImage > 110; %imbinarize(grayImage);
% Display the mask.
subplot(3, 2, 2);
imshow(mask, []);
impixelinfo;
title('Initial Binary Image');
%display the boundaries
boundaries = bwboundaries (mask);
numberOfBoundaries = size(boundaries,1);
subplot(3, 2, 3);
imshow(grayImage);
hold on;
for k = 1 : length(boundaries)
thisBoundary = boundaries{k};
x = thisBoundary(:, 2);
y = thisBoundary(:, 1);
plot(x, y, 'r-', 'LineWidth', 2);
end
title('Image With Boundaries')

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by