Find the moving circle position between two images

4 visualizaciones (últimos 30 días)
Doga Selcuk
Doga Selcuk el 9 de Oct. de 2022
Comentada: Doga Selcuk el 11 de Oct. de 2022
Hey,
I was trying to write a code that evaluate the position vector of a circle with using two pictures. For example, in the first picture circle is on the (8,8) and in the second picture it will be (11,13). How can i calculate the position vector with using same size potographs?
Actually my goal is compare different at least 4 or five pictures which they captured to position of a circle. If i can understand two i think i can apply for all.
Thank you for your time.
Note: I will use colour dedection to find circle. Example :The circle will be green and the background will be all white.

Respuesta aceptada

Image Analyst
Image Analyst el 9 de Oct. de 2022
You can use image analysis, expecially the Color Thresholder app on the Apps tab of the tool ribbon.
Also see my Image Processing Tutorial in my File Exchange:
If you have any more questions, then attach your images and code to read them in with the paperclip icon after you read this:
  3 comentarios
Image Analyst
Image Analyst el 9 de Oct. de 2022
Editada: Image Analyst el 10 de Oct. de 2022
Where did you check? I mean certainly you need to have images so it you checked your drive(s) and can't find your images, then there is nothing to do.
If you have images, then you can use segmentation methods on it, such as one or more of the ones in my file exchange or from code you export from the Color Thresholder app.
See attached demo where I track a green Sharpie marker. See if that helps.
Again, I can't offer more customized help unless you attach your images.
Or you could try imfindcircles
Doga Selcuk
Doga Selcuk el 10 de Oct. de 2022
Thanks a lot. I will try to upload images ASAP.

Iniciar sesión para comentar.

Más respuestas (1)

Image Analyst
Image Analyst el 10 de Oct. de 2022
Try this:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 16;
%===============================================================================
% Get the name of the background image the user wants to use.
baseFileName = 'coloredchips.png';
folder = pwd;
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~exist(fullFileName, 'file')
% The file doesn't exist -- didn't find it there in that folder.
% Check the entire search path (other folders) for the file by stripping off the folder.
fullFileNameOnSearchPath = baseFileName; % No path this time.
if ~exist(fullFileNameOnSearchPath, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist in the search path folders.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
%=======================================================================================
% Read in demo image.
rgbImage = imread(fullFileName);
% Get the dimensions of the image.
[rows, columns, numberOfColorChannels] = size(rgbImage)
% Display image.
subplot(2, 2, 1);
imshow(rgbImage, []);
impixelinfo;
axis on;
caption = sprintf('Original RGB Image\n%s', baseFileName);
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
hp = impixelinfo(); % Set up status line to see values when you mouse over the image.
% Set up figure properties:
% Enlarge figure to full screen.
g = gcf;
g.WindowState = "maximized";
% Get rid of tool bar and pulldown menus that are along top of figure.
% set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
drawnow;
%=======================================================================================
% Threshold the image to create a mask
[mask, maskedRGBImage] = createMask(rgbImage);
% Fill holes
mask = imfill(mask, 'holes');
% Display the mask image.
subplot(2, 2, 2);
imshow(mask, []);
impixelinfo;
axis('on', 'image');
title('Mask Image', 'FontSize', fontSize);
drawnow;
%=======================================================================================
% Plot the borders of all the blobs in the overlay above the original background 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.
% 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
% Here is where we actually plot the boundaries of each blob in the overlay.
subplot(2, 2, 3);
imshow(rgbImage);
hold on; % Don't let boundaries blow away the displayed image.
for k = 1 : numberOfBoundaries
thisBoundary = boundaries{k}; % Get boundary for this specific blob.
x = thisBoundary(:,2); % Column 2 is the columns, which is x.
y = thisBoundary(:,1); % Column 1 is the rows, which is y.
plot(x, y, 'r-', 'LineWidth', 2); % Plot boundary in red.
end
hold off;
caption = sprintf('Original image with %d detected green blobs', numberOfBoundaries);
title(caption, 'FontSize', fontSize);
axis('on', 'image'); % Make sure image is not artificially stretched because of screen's aspect ratio.
%=======================================================================================
% Find the centroid of the green blobs.
props = regionprops(mask, 'Centroid');
xyCentroids = vertcat(props.Centroid)
xCentroid = xyCentroids(:, 1);
yCentroid = xyCentroids(:, 2);
%=======================================================================================
% Plot a big red cross over the centroids.
hold on;
plot(xCentroid, yCentroid, 'r+', 'LineWidth', 2, 'MarkerSize', 30);
message = sprintf('Done!')
uiwait(helpdlg(message));
%=======================================================================================
function [BW,maskedRGBImage] = createMask(RGB)
%createMask Threshold RGB image using auto-generated code from colorThresholder app.
% [BW,MASKEDRGBIMAGE] = createMask(RGB) thresholds image RGB using
% auto-generated code from the colorThresholder app. The colorspace and
% range for each channel of the colorspace were set within the app. The
% segmentation mask is returned in BW, and a composite of the mask and
% original RGB images is returned in maskedRGBImage.
% Auto-generated by colorThresholder app on 10-Oct-2022
%------------------------------------------------------
% Convert RGB image to chosen color space
I = rgb2hsv(RGB);
% Define thresholds for channel 1 based on histogram settings
channel1Min = 0.303;
channel1Max = 0.528;
% Define thresholds for channel 2 based on histogram settings
channel2Min = 0.446;
channel2Max = 1.000;
% Define thresholds for channel 3 based on histogram settings
channel3Min = 0.292;
channel3Max = 1.000;
% Create mask based on chosen histogram thresholds
sliderBW = (I(:,:,1) >= channel1Min ) & (I(:,:,1) <= channel1Max) & ...
(I(:,:,2) >= channel2Min ) & (I(:,:,2) <= channel2Max) & ...
(I(:,:,3) >= channel3Min ) & (I(:,:,3) <= channel3Max);
BW = sliderBW;
% Initialize output masked image based on input image.
maskedRGBImage = RGB;
% Set background pixels where BW is false to zero.
maskedRGBImage(repmat(~BW,[1 1 3])) = 0;
end
  7 comentarios
Image Analyst
Image Analyst el 11 de Oct. de 2022
For our complicated tracking needs, we use Noldus software:
Ask them if your windtunnel situation could use their software.
Or else I'm sure there are wind tunnel software programs commercially available, so why write your own?
Doga Selcuk
Doga Selcuk el 11 de Oct. de 2022
I will, thank you.
I just want to use Matlab software and actually im a seniour student so another point is it's kinda challenge for me to do with matlab but as i said there are limited examples in matlab as i see. I think you're right

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