필터 지우기
필터 지우기

circle centered on the object

조회 수: 4 (최근 30일)
Tomescu
Tomescu 2011년 12월 22일
I have a reference image that contains 10 items. I have separate objects in small images (cut from the reference image). Code sequence must find an object that you selected (if the write code sequence "object 1" must make a circle around the "object 1" If it says "Objective 2" to make the circle around the "item 2" Can you help me please? reference image
Object
clear; clc;
I = imread('di-5Y01.jpg');
object = imread('di-FNMJ.jpg');
c = normxcorr2(object(:,:,1),I(:,:,1));
[max_c, imax] = max(abs(c(:)));
[ypeak, xpeak] = ind2sub(size(c),imax(1));
corr_offset = [(xpeak-size(object,2)) (ypeak-size(object,1))];
figure, imshow(I); hold on;
rectangle('position',[corr_offset(1) corr_offset(2) 30 60],...
'curvature',[1,1],'edgecolor','g','linewidth',2);
Code sequence works but not centered the circle on the object.

채택된 답변

Chandra Kurniawan
Chandra Kurniawan 2011년 12월 22일
Hello, Why don't you use rectangle??
Why must circle??
I have my code detect the exact area if you consider to use rectangle??
Would you use rectangle? Then I'll give u the code
Here the results :
Object 1:
Object 2:
Object 3:

추가 답변 (3개)

Chandra Kurniawan
Chandra Kurniawan 2011년 12월 22일
Here the code if you consider to use rectangle
I = imread('di-5Y01.jpg');
object = imread('obiect1.jpg');
[m n o] = size(object);
c = normxcorr2(object(:,:,1),I(:,:,1));
[max_c, imax] = max(abs(c(:)));
[ypeak, xpeak] = ind2sub(size(c),imax(1));
corr_offset = [(xpeak-size(object,2)) (ypeak-size(object,1))];
figure, imshow(I); hold on;
rectangle('position',[corr_offset(1) corr_offset(2) n m],...
'edgecolor','g','linewidth',2)
I hope this helps you :)
  댓글 수: 1
Tomescu
Tomescu 2011년 12월 22일
Thank you very much!

댓글을 달려면 로그인하십시오.


Chandra Kurniawan
Chandra Kurniawan 2011년 12월 22일
Hello, It's quite simple.
You just need to increase or decrease the 'corr_offset' values with small random value.
I = imread('di-5Y01.jpg');
object = imread('di-FNMJ.jpg');
c = normxcorr2(object(:,:,1),I(:,:,1));
[max_c, imax] = max(abs(c(:)));
[ypeak, xpeak] = ind2sub(size(c),imax(1));
corr_offset = [(xpeak-size(object,2)) (ypeak-size(object,1))];
figure, imshow(I); hold on;
rectangle('position',[corr_offset(1)-9 corr_offset(2)+5 45 45],...
'curvature',[1,1],'edgecolor','g','linewidth',2);
The result :
  댓글 수: 3
Chandra Kurniawan
Chandra Kurniawan 2011년 12월 22일
Hello, Why don't you use rectangle??
Why must circle??
I have my code detect the exact area if you consider to use rectangle??
Would you use rectangle? Then I'll give u the code
Tomescu
Tomescu 2011년 12월 23일
Hello!
I found this code on another forum.
The problem is that I think it's a bit complet.Can you look over it please?
Thank you.
%#read & convert the image
imgCol = imread('http://i.stack.imgur.com/tbnV9.jpg');
imgGray = rgb2gray(img);
obj = rgb2gray(imread('http://i.stack.imgur.com/GkYii.jpg'));
%# cross-correlate and find the offset
corr = normxcorr2(...);
[~,indx] = max(abs(corr(:))); %# Modify for multiple instances (generalize)
[yPeak, xPeak] = ind2sub(...);
corrOffset = [yPeak - ..., xPeak - ...];
%# create a mask
mask = zeros(size(...));
mask(...) = 1;
mask = imdilate(mask,ones(size(...)));
%# plot the above result
h1 = imshow(imgGray);
set(h1,'AlphaData',0.4)
hold on
h2 = imshow(imgCol);
set(h2,'AlphaData',mask)

댓글을 달려면 로그인하십시오.


Tomescu
Tomescu 2011년 12월 22일
The ptoject say that the object must be identify in a circle, but i hope that it whont be a problem if is in a rectangle.
  댓글 수: 1
Chandra Kurniawan
Chandra Kurniawan 2011년 12월 22일
So, how about your own decision?
You'll stay use circle with non exact area or
You'll use rectangle with exact area.
You can ask your professor about it :)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Feature Detection and Extraction에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by