이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
how to get the movement of an object with respect to time in MATLAB?
조회 수: 2 (최근 30일)
이전 댓글 표시
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
yanqi liu
2021년 12월 23일
yes,sir,may be upload the image list to detect object and trace the left edge as target
답변 (1개)
Image Analyst
2021년 12월 22일
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
Tayyaba Bano
2021년 12월 23일
Thanks for your reply, I used the following code to generate the boundary. But the biundaries are not clear may be because the image has a lot of small particles. I am also attaching the image of boundary I have attained for the Im1.
grayImage = imread('Im1.bmp');
[rows, columns, numberOfColorChannels] = size(grayImage);
if numberOfColorChannels > 1
grayImage = rgb2gray(grayImage);
end
% Display the image.
%--------------------------------------------------------------------------------------------------------
% SEGMENTATION OF IMAGE
% Get a binary image
mask = grayImage < 38; %imbinarize(grayImage);
% Display the mask.
subplot(2, 3, 4);
imshow(mask, []);
impixelinfo;
title('Initial Binary Image');
impixelinfo;
% Make a circle mask to get rid of corners
% Create a logical image of a circle with specified
% diameter, center, and image size.
% First create the image.
imageSizeX = columns;
imageSizeY = rows;
[columnsInImage, rowsInImage] = meshgrid(1:imageSizeX, 1:imageSizeY);
% Next create the circle in the image.
centerX = columns/2;
centerY = rows/2;
% radius = max(centerX, centerY);
radius = 100;
circlePixels = (rowsInImage - centerY).^2 ...
+ (columnsInImage - centerX).^2 <= radius.^2;
mask = mask & circlePixels;
% Fill interior holes.
mask = imfill(mask, 'holes');
props = regionprops(mask, 'Area');
allAreas = sort([props.Area], 'ascend')
mask = bwareaopen(mask,100);
subplot(2, 3, 5);
imshow(mask, []);
impixelinfo;
title('Final Binary Image');
impixelinfo;
boundaries = bwboundaries(mask);
subplot(2, 3, 6);
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')
Image Analyst
2021년 12월 23일
편집: Image Analyst
2021년 12월 23일
Why are you creating a circular mask???
Does the spotty background also move or does it stay fixed?
Tayyaba Bano
2021년 12월 23일
Because the small particles are of cicular cross section, therefore to hide them.
Image Analyst
2022년 2월 7일
But there are small noise particles all over. You don't need a mask of that shape to get rid of them. You can use bwareafilt() and not use any mask. I still think my way is better but you're free to ignore it and use your own way.
% Demo by Image Analyst
% Initialization Steps.
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 = 'slide.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;
% Maximize window.
g = gcf;
g.WindowState = 'maximized'
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 = 16;
row1 = find(verticalProfile > thresholdValue, 1, 'first');
row2 = find(verticalProfile > thresholdValue, 1, 'LAst');
grayImage = grayImage(row1:row2, :);
% Display the histogram.
subplot(3, 2, 2);
imhist(grayImage);
grid on;
impixelinfo;
title('Histogram', 'FontSize', fontSize);
drawnow; % Force screen to refresh immediately.
% Get a binary image
thresholdValue = 39;
xline(thresholdValue, 'Color', 'r', 'LineWidth', 2)
mask = grayImage > thresholdValue;
% For noise reduction, Fill any potential holes and take the largest blob.
mask = bwareafilt(imfill(mask, 'holes'), 1);
% grayImage = adapthisteq(grayImage, "NumTiles",[16, 16]);
% grayImage = medfilt2(grayImage, [27, 7]);
mask = edge(grayImage, "canny");
[filteredImage,estDoS] = imnlmfilt(grayImage, 'DegreeOfSmoothing', 15);
filteredImage = imtophat(filteredImage, true(3, 35));
% Display the image.
subplot(3, 2, 3);
imshow(filteredImage, []);
axis('on', 'image')
impixelinfo
lowThreshold = 17;
highThreshold = 255;
% [lowThreshold, highThreshold] = threshold(lowThreshold, highThreshold, filteredImage)
% Get a mask for spots
spots = filteredImage > lowThreshold;
% props = regionprops(spots, 'Area');
% allAread = sort([props.Area])
% Get rid of any spots less than 1000 pixels.
spots = bwareafilt(spots, [1, 1000]);
% 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 original image again.
subplot(3, 2, 6);
imshow(grayImage, []);
impixelinfo;
axis('on', 'image');
title('Outlined', 'FontSize', fontSize);
hold on
drawnow;
verticalThreshold = 20;
row1 = find(verticalProfile > verticalThreshold, 1, 'first');
row2 = find(verticalProfile > verticalThreshold, 1, 'last');
yline(row1, 'Color', 'r', 'LineWidth', 2);
yline(row2, 'Color', 'r', 'LineWidth', 2);
horizontalThreshold = 75;
col1 = find(horizontalProfile > horizontalThreshold, 1, 'first');
col2 = find(horizontalProfile > horizontalThreshold, 1, 'last');
xline(col1, 'Color', 'r', 'LineWidth', 2);
xline(col2, 'Color', 'r', 'LineWidth', 2);
% % Plot the borders of all the blobs in the overlay above the original grayscale image
% % using the coordinates returned by bwboundaries().
% % bwboundaries() returns a cell array, where each cell contains the row/column coordinates for an object in the image.
% subplot(3, 2, 4);
% imshow(grayImage); % Optional : show the original image again. Or you can leave the binary image showing if you want.
% hold on;
% % Here is where we actually get the boundaries for each blob.
% boundaries = bwboundaries(mask);
% % boundaries is a cell array - one cell for each blob.
% % In each cell is an N-by-2 list of coordinates in a (row, column) format. Note: NOT (x,y).
% % Column 1 is rows, or y. Column 2 is columns, or x.
% numberOfBoundaries = size(boundaries, 1); % Count the boundaries so we can use it in our for loop
Tayyaba Bano
2022년 2월 15일
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
2022년 2월 15일
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')
참고 항목
카테고리
Help Center 및 File Exchange에서 Computer Vision with Simulink에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)