finding circles and tracking
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
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!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 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)
