Thursday 15 March 2012

matlab - Using Masks in Template Matching -



matlab - Using Masks in Template Matching -

i wondering if help explain how utilize masks when doing template matching. specifically, trying in matlab, if explain logic , can figure out implement myself. have tried multiple net searches , have not been able find clear answer.

in reply post below, mask never defined , haven't been able find explain how incorporate thought should seek question more general angle in hopes can figure out there.

matching object outer shape using normalized cross correlation

thank help

that post you're referring provided reply to, though wasn't accepted answer. i'm surprised didn't see previous post made until point, , sincerely apologize that.

normally, when you're doing template matching, utilize all of pixels in template , want utilize template search in matching image. in post, op had template, wanted include pixels within template. template rectangular part has stuff in it... whether grayscale intensities, colour pixels, etc representation of you're trying find in matching image.

in post, not all of pixels in part included in template. specifically, some of pixels in template specified should part of correlation matching. these pixels included in template specified mask, you're looking in post. op of post you're referring wanted find circular object ignoring within actual circle itself.

therefore, within template, used mask extract pixels should part of correlation matching. normally, normalized cross-correlation of pixels in template of pixels in part of same size in matching image. post you're referring to, within template, mask specifies which pixels should part of matching. white pixels should included in matching, while black should ignored.

if @ mask in op's post in case, looks circular object itself, disregarding pixels within circular object. contents within circular object not important. want observe general circular shape. if include these pixels within object part of template, may not able find circular object due noise contained within object.

the reason why can't find on topic because template matching seldom ignores pixels within template. want utilize much info can in order seek , create matching more robust. post you're referring special case specific op's application.

edit

now understand after, want define mask programatically. in particular, want define circular mask seen in post you're referring to. simple code in matlab. circular ring see has two radii: inner ring , outer ring. compute euclidean distance centre of image each point in mask. points >= radius of inner ring , <= radius of outer ring set true while else set false. such, general steps are:

specify dimensions of mask want, inevitably depend on size of template , want match size. also, need specify inner , outer radius of circular mask. generate 2d grid of co-ordinates (0,0) centre of the image. utilize meshgrid you. compute euclidean distance centre each point in image. for each distance calculated, check see if point >= inner ring radius , <= outer ring radius. if is, set true, , false otherwise.

as such:

%// dimensions of image %// alter here accordingly rows = 101; cols = 101; %// radii - alter accordingly %// inner ring radius inner_radius = 20; %// outer ring radius outer_radius = 40; %// define grid of points [x,y] = meshgrid(-floor(cols/2):floor(cols/2), -floor(rows/2):floor(rows/2)); %// find euclidean distance respect centre of image dists = sqrt(x.^2 + y.^2); %// find points within inner , outer radii out = dists >= inner_radius & dists <= outer_radius; %// cap ensure same mask size out = out(1:rows,1:cols);

take special care of lastly statement. if specify odd dimensions, respect centre of mask, co-ordinates relative centre correct. example, if chose rows 101, should span -50 50, including centre corresponds 101 points. should specify...say...100, when using meshgrid, still co-ordinates -50 50, , still give mask of 101 points in vertical direction (rows). create sure have template conforms dimensions specify, want sure extract out same amount of rows , columns specified in origin after calculate mask. difference single pixel border, shouldn't matter... if you're stickler , want same dimensions, you'll need do.

if specify rows = 101, cols = 101, inner_radius = 20, outer_radius = 40, mask get:

matlab image-processing mask matching

No comments:

Post a Comment