So I’m trying to identify the boundaries of a crack in a test specimen using image processing by simply thresholding>dilating then taking the difference of it. but I’m facing a problem the issue is the input data has these pixels which has pixel intensity equal or near to the crack pixel intensity so the the code thinks that also is a crack. How can I solve this? I Tried filtering but it doesn’t work and changing thresholds also doesn’t work. I have attached few pics for reference.
The Places i have circled in red is something i don’t want that is i want it to be black. And the green ones i need to be proper white boundaries.
If the crack is always going to be the largest contour, you could filter based on contour size and only keep the largest one. I notice, however, that the far left part of the crack appears to have been isolated as a small contour (not contiguous with the main crack contour), so that might be an issue. And, of course, you have shown only one image. Developing an image processing sequence that works well for this image might be fairly straightforward, but would it work for all/most of your other images? Probably not.
Try filtering by contour size and see how far that gets you, and then post a representative sample of the images you will be processing.
No actually i have a test in which a camera captures frames from applying load to complete fracture of sample. So initially there wont be a crack. The one I attached is the last frame . So not always the crack wont be the largest contour. I tried to automate image J and you know mask these defects with a white fill but the issue is the sample is moving bcs of deformation so at different times the defects are not at the same location.
Anyways i will try what you suggested and will share the result.
a video of that camera perspective would probably help understand the situation.