matlabimage-processingdetectionmathematical-morphology

HitMiss transformation in matlab


I'm performing Hit and Miss transformation on

enter image description here

with

enter image description here

but it's not producing nonzero detection result.

clear all,close all,clc
img=im2bw(imread('bw.jpg'));
B=im2bw(imread('B.jpg'));

find=B;
diff=imdilate(find,strel('square',3))-find;
sam=nonzeros(bwhitmiss(img,find,diff))

what's the problem??


Solution

  • Hit or miss only works if the shape you want to detect in the matching image is exactly the same as the input query. The B you are using is not the same shape or size as the B in the image you want to detect it in, and that's why you're not getting results. You need to use something more sophisticated than morphology to detect the B.