How to compare two images from each other: Round 2
Mostrar comentarios más antiguos
Hello again!
Slightly stuck on this issue. I need help on finding a way for MatLab to follow an object from one picture to the next, automatically. I've written a small script from help online that allows me to select the object and determine its coordinates, but is there a way that MatLab can see the object without me manually tracing it?
Thanks!,
-Frank
Images:


Code:
I = imread('rice.png');
%%imshow(I)
background = imopen(I,strel('disk',15));
figure, surf(double(background(1:8:end,1:8:end))),zlim([0 255]);
set(gca,'ydir','reverse');
%%Darkens image
I2 = I - background;
%figure, imshow(I2)
%%Increases contrast
I3 = imadjust(I2);
%figure, imshow(I3);
%%Turns image into binary colors (Black and White)
level = graythresh(I3);
bw = im2bw(I3,level);
bw = bwareaopen(bw, 50);
%%figure, imshow(bw)
cc = bwconncomp(bw, 4);
cc.NumObjects
%%Select grain connected to background
grain = false(size(bw));
grain(cc.PixelIdxList{50}) = true;
figure, imshow(grain);
labeled = labelmatrix(cc);
whos labeled
%%Color Shift
RGB_label = label2rgb(labeled, @autumn, 'c', 'shuffle');
figure, imshow(RGB_label)
graindata = regionprops(cc, 'basic');
graindata(1).Area
%%Grain area
grain_areas = [graindata.Area];
[max_area, idx] = max(grain_areas);
grain = false(size(bw));
grain(cc.PixelIdxList{idx}) = true;
figure, imshow(grain)
%%Select a portion to allocate coordinates of object
[x, y, ~, xi, yi] = roipoly(grain);
BW = roipoly(100, 200, xi, yi);
%%Displays xi, yi coordinates
figure, imshow(BW)
grain2 = imread('Rice3.gif');
[x2,y2,Bw,xi2, yi2] = roipoly(grain2);
1 comentario
Frank
el 13 de Mayo de 2011
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre ROI-Based Processing en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!