MATLAB: Image Edge Detection Using Edge Function

image processingImage Processing ToolboxMATLAB

I would like to detect edges in the image in the attached TestImage.jpg. I've highlighted my region of interest in (ROI.jpg). I would not like to use a fixed ROI matrix as different images may not always fit the mask. So I would like to do some edge detection to automatically detect my ROI. I've tried the following:
% Read image as gray scale
I = rgb2gray(imread('TestImage.jpg'));
I = im2double(I);
BW = edge(I,'Canny',0.75,sqrt(150));
image(BW,'CDataMapping','scaled')
The results (DetectedEdges.jpg) does not seem to resolve all the edges I require. I've tried different threshold values as well. Is there a better way of getting my ROI?

Best Answer

First I'd get a first shot at the mask by thresholding. Luckily much of the surround is white so thresholding will get the bottom and sides. Then I might try a texture filter, like stdfilt(), because you know your object of interest is rough while the curved bars/rods behind it are smooth. Then threshold that texture mask and AND it with your intensity thresholding mask. If that doesn't work, post the code for it and we can start tweaking it.