I am using HALCON for NCC model matching and encountering issues when both the template and search images are preprocessed with median and Gaussian filters. Initially, the model matching works fine without any preprocessing, but as soon as I apply these filters, the system fails to find any matches.
Here is the approach I used:
- I preprocessed the template and search images by applying median filters to enhance feature clarity and reduce noise, hoping this would increase matching precision.
- I expected these preprocessing steps to refine the search results by making feature matching more robust against variations in the images.
However, after preprocessing, the system does not find any matches at all, which is contrary to my expectations. I have been successful in finding matches when no preprocessing is applied.
Here’s image:
Here’s the relevant portion of the HALCON code I used for preprocessing and model matching:
dev_update_off ()
read_image (Image, '/path/to/image')
rgb1_to_gray (Image, Image)
gen_rectangle2 (ROI_0, 787.918, 1230.2, rad(-63.4002), 35.6442, 16.917)
gen_rectangle2 (ROI_1, 812.479, 1174.2, rad(25.4552), 43.8777, 18.743)
union2 (ROI_0, ROI_1, TemplROI)
gen_rectangle1 (TemplROI, 651.727, 887.226, 731.119, 932.425)
reduce_domain(Image, TemplROI, templimage)
median_image(templimage, templimage, 'circle', 2, 'mirrored')
* create model
create_ncc_model (templimage, 'auto', -0.39, 6.29, 'auto', 'use_polarity', NCCModelID)
** Reduce domain
threshold (Image, Region, 0, 80)
fill_up (Region, RegionFillUp)
connection (RegionFillUp, ConnectedRegions)
select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 150, 10e3)
dilation_circle (SelectedRegions, RegionDilation, 70.5)
union1 (RegionDilation, RegionUnion)
reduce_domain (Image, RegionUnion, ImageReduced)
median_image(ImageReduced, ImageReduced, 'circle', 2, 'mirrored')
* find model
dev_clear_window()
dev_display(Image)
find_ncc_model(ImageReduced, NCCModelID, -0.39, 6.29, 0.6, 0, 0.6, 'true', 0, Row, Column, Angle, Score)
dev_display_ncc_matching_results(NCCModelID, 'red', Row, Column, Angle, 0)
dev_disp_text (Score, 'image', Row, Column, 'black', [], [])
stop()
Could anyone help identify why preprocessing adversely affects the model matching and suggest adjustments to improve the outcomes? If possible, please share visual results from similar situations, including search images, template images, and images showing failed and successful matches.