finding circles and tracking
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
hello I am new to MATLAB and I faced this problem as a university project I have to find circles the original image had really poor lighting I got this result after pre processing. now I have problem detecting circles and tracking them.its a stack (.tif) 200 images and particles have a different location in each image. is there any code out there or any algorithm can help me in this project?
採用された回答
Image Analyst
2017 年 8 月 23 日
[Laughing and sighing] OK, who told you to do an edge detection to find the circle? Some other novice I suppose. I don't know why but for some reason people who don't know much about image processing seem to think "Step 1" of every image analysis algorithm starts with edge detection. It's just not true. In fact, in most of those cases, a simple thresholding would be preferable, as it is in your situation. So simply threshold, then call regionprops. Something like
binaryImage = grayImage < someThreshold; % someThreshold is something like 30 or 60 or whatever works.
binaryImage = bwareafilt(binaryImage, 1); % Extract largest blob only.
labeledImage = bwlabel(binaryImage);
props = regionprops(labeledImage, 'Centroid');
xCentroid = props.Centroid(1);
yCentroid = props.Centroid(2);
See my Image Processing Tutorial http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862&sort=downloads_desc for a full demo using the "coins" demo image that ships with MATLAB.
15 件のコメント
sanaz hajjami
2017 年 8 月 23 日
this is the result of simple thresholding since the lighting is poor. do you have any suggestion?:) or may you tell me where I am wrong?
Image Analyst
2017 年 8 月 23 日
編集済み: Image Analyst
2017 年 8 月 23 日
You picked the wrong threshold. Use 120. You can use the attached triangle thresholding method if you want an automatic way (only if the intensity varies).
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 short g;
format compact;
fontSize = 25;
%===============================================================================
% Get the name of the image the user wants to use.
baseFileName = 'original1.jpg';
% Get the full filename, with path prepended.
folder = []; % Determine where demo folder is (works with all versions).
fullFileName = fullfile(folder, baseFileName);
%===============================================================================
% Read in a demo image.
grayImage = imread(fullFileName);
% 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.
% Use weighted sum of ALL channels to create a gray scale image.
% grayImage = rgb2gray(grayImage);
% ALTERNATE METHOD: Convert it to gray scale by taking only the green channel,
% which in a typical snapshot will be the least noisy channel.
grayImage = grayImage(:, :, 2); % Take green channel.
end
% Display the image.
subplot(2, 2, 1);
imshow(grayImage, []);
axis on;
axis image;
caption = sprintf('Original Gray Scale Image');
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
drawnow;
hp = impixelinfo();
% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0, 1, 1]);
% 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;
% Display the histogram.
histogram(grayImage);
grid on;
title('Histogram of Gray Scale Image', 'FontSize', fontSize, 'Interpreter', 'None');
% Binarize the image.
threshold = 120;
hold on;
line([threshold, threshold], ylim, 'Color', 'r'); % Draw line at threshold over histogram.
binaryImage = grayImage < threshold; % Determine number from histogram.
% Get rid of black border
binaryImage = imclearborder(binaryImage);
% Extract only the largest blob.
binaryImage = bwareafilt(binaryImage, 1);
% Fill the holes in the largest blob.
binaryImage = imfill(binaryImage, 'holes');
% Display the image.
subplot(2, 2, 3:4);
imshow(binaryImage, []);
axis on;
axis image;
caption = sprintf('Binary Image');
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
drawnow;
hp = impixelinfo();
% Label the image
[labeledImage, numBlobs] = bwlabel(binaryImage);
% Make measurements of Centroid and Area
props = regionprops(labeledImage, 'Area', 'Centroid');
xCentroid = props.Centroid(1);
yCentroid = props.Centroid(2);
hold on;
plot(xCentroid, yCentroid, 'r+', 'LineWidth', 2, 'MarkerSize', 30);
caption = sprintf('Binary Image with centroid at (%.2f, %.2f) marked', ...
xCentroid, yCentroid);
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');

sanaz hajjami
2017 年 8 月 23 日
thanks for your help it gave me the idea. but I need to find the location and track all those small particles around.this is a simulation of granular fluid so I have to catch how all the particles move.and their locations in all 200 frames.
Image Analyst
2017 年 8 月 23 日
OK, so just save the centroid into an array where you have one centroid for every image. You didn't ask a question this time so I assume you know how to do that.
sanaz hajjami
2017 年 8 月 23 日
nice.you are so helpful. but can you explain more? I am not sure if I get what you mean.because by using normal threshold I will miss many particles especially on the borders. maybe I ask my question in a confusing way.what I need is to track and find all the circles around. more than 500 circles in each frame and we have 200 frames. how can I detect all of them? do I need to threshold separately for each particle?
Image Analyst
2017 年 8 月 24 日
Do you mean the really faint things on the bottom half of the image (that I didn't know were circles)? I was just finding the big black circle in the middle of the image.
If so, I'd probably try pattern matching via normalized cross correlation. I attach a demo.
sanaz hajjami
2017 年 8 月 24 日
unfortunately yes! those faint things! so, in this case, pre processing can not do much? (btw the shape is circle and all have the same size.) but what you mean is that with this code that u gave me I can catch the position of them one by one and then put them in the array? so I will be able to use that array for tracking them while moving in all frames? because these are granular fluid particles and they are moving.
Image Analyst
2017 年 8 月 24 日
Yes, normxcorr2() should work since it basically scans the image looking for a template and giving a high signal when the template is found, and a low signal where it's not found or misaligned.
sanaz hajjami
2017 年 8 月 25 日
I did a bit of searching today about pattern matching since I did not have any idea about it. do you have any code suitable to my case?
Image Analyst
2017 年 8 月 25 日
Go back up a few comment ago. I think you overlooked my attached demo on normxcorr2().
sanaz hajjami
2017 年 8 月 25 日
I'd seen it. and I tried it but I can not get the satisfied result.I think I need to know more about it.Thanks dear Image Analyst !
sanaz hajjami
2017 年 8 月 25 日
let me know where I did not get the concept. this is the result of your demo. but I want to find all the particles or at least most of them since they have the same size. but it finds only one that I chose as a template. where am I wrong?
Image Analyst
2017 年 8 月 25 日
It looks like your original image is messed up - it looks like you binarized it somehow. Use your original image. Then it looks like the template is not right. Are you sure you cut it out of the original image right over/centered a small circle?
sanaz hajjami
2017 年 8 月 25 日
OK I will fix them and show you the result but it suppose to find whatever is close to the template right? it can detect multi particles right? just to have an idea where I am making mistake.
sanaz hajjami
2017 年 8 月 25 日
it found only one particle again.I don't know where I am making mistake
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Particle & Nuclear Physics についてさらに検索
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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)
