Edge detection with DIC pattern.

Need some help/advice with an edge detection method. I am looking at edge of cylinderical sample that contains a DIC pattern. I have tried some various basic stuff like the edge() and hough transformation, but I either have all of the DIC pattern showing in the edge image, or the edge of the sample is incomplete and no good.
anyone have any experience with this and could point me in the right direction please?

 采纳的回答

Umar
Umar 2024-8-19

Hi @Tom Lancaster ,

To effective detect edges on a cylindrical sample with a DIC pattern, I will consider employing a combination of preprocessing and advanced edge detection techniques.

First, start by applying a Gaussian filter to reduce noise, which can interfere with edge detection. You can use the following MATLAB code snippet:

% Read the image
img = imread('your_cylindrical_sample.jpg');
   % Convert to grayscale
    grayImg = rgb2gray(img);
   % Apply Gaussian filter
   filteredImg = imgaussfilt(grayImg, 2);

Note: For more information on this function, please refer to

https://www.mathworks.com/help/images/ref/imgaussfilt.html?s_tid=doc_ta

Next, utilize the edge() function with the 'Canny' method, which is particularly effective for detecting edges in images with varying intensity:

   % Perform edge detection
   edges = edge(filteredImg, 'Canny');

If the DIC pattern still overwhelms the edges, consider using morphological operations to refine the edge map. For instance, you can use imopen() to remove small objects:

% Morphological opening
se = strel('disk', 2);

Note: for more information on this function, please refer to

https://www.mathworks.com/help/images/ref/strel.html

cleanedEdges = imopen(edges, se);

Finally, visualize the results to ensure the edges of the cylindrical sample are clearly defined. Adjust the parameters as necessary to optimize the detection for your specific image. Let me know if you have any further questions.

8 个评论

Hi This has worked better than my previous attempts thanks!
I still am struggling to extract just the cylinder out line however. Could i extract the two edges lines without further image processing do you think? Best Tom

Hi @Tom Lancaster ,

Glad to know it helped resolve your problem. Now, to extract the outline of a cylinder from a DIC pattern without extensive image processing, you can focus on isolating the two edge lines directly after applying the Canny edge detection. After obtaining the edge map, you can use the bwboundaries function to identify the boundaries of the detected edges. Here’s a concise approach:

% Read and preprocess the image
   img = imread('your_cylindrical_sample.jpg');
    grayImg = rgb2gray(img);
    filteredImg = imgaussfilt(grayImg, 2);
     edges = edge(filteredImg, 'Canny');
     % Extract boundaries
    [B, L] = bwboundaries(edges, 'noholes');

Note: For more information on this function, please refer to

https://www.mathworks.com/help/images/ref/bwboundaries.html

    % Visualize the boundaries
     imshow(grayImg); hold on;
     for k = 1:length(B)
     boundary = B{k};
     plot(boundary(:,2), boundary(:,1), 'r', 'LineWidth', 2);
     end
     hold off;

So, in this provided code, it will help you visualize the detected edges, allowing you to focus on the cylinder's outline. If the results are not satisfactory, consider adjusting the parameters of the edge function or applying additional morphological operations selectively to enhance the edge detection. Hope this helps. Let me know if you need further assistance!

@Tom Lancaster, which one of those squiggles and lines is the "Cylinder"? Also, could you post the original DIC image in the body of your message rather than as a .fig file (where people would have to switch to MATLAB and open to see it)? I'll check back later today.
The white cylinder with the black speckles is what I want to detect the edges off
So the bowtie-shaped thing on the right hand side of the image? Can you attach the actual image, instead of a screenshot. I mean the PNG image file.
And once you get the edges of the cylinder, then what?
And is that part in the same position in every image, so we can just use a fixed template to locate and process it? If not in exactly the same location, is it in at least the approximate location, like it's always somewhere in the right side so we can just clean up some clutter by blackening the left side of the image?
What does DIC mean? It does not look like Differential Interference Contrast microscope images like I thought you meant.
So yh its the white dogbone shape with the black speckles. DIC is digital image correlation, what happens is the cylinder is pulled to the left (right side is held fixed). This leads to the cylinder reducing in area and the length increase. until it necks (like when you pull chewing gum). I can crop the image before image processing but anything left of the dog bone needs to stay as the sample will eventually come in to view here.
So eventually what I want to be able to do is track how the thickness of the white dog bone (y direction). changes with each image, up and down the length of the white shape. Does this make sense?
I should add that I have tried to use the bw area open function to filter out min length edges, but the issue is that sometimes the outline of the dogbone isn't continous, hence it filters out some of that edge.
%% Image Processing work
% Read the image
img = imread('Inconel600C10-2.chan 10000.tif');
% Convert to grayscale
grayImg = im2gray(img);
% Apply Gaussian filter
filteredImg = imgaussfilt(grayImg, 2);
% Perform edge detection
edges = edge(filteredImg, 'Canny');
[B, L] = bwboundaries(edges, 'noholes');
% Visualize the boundaries
figure();
imshow(grayImg); hold on;
for k = 1:length(B)
boundary = B{k};
plot(boundary(:,2), boundary(:,1), 'r', 'LineWidth', 1);
end
hold off;
% Morphological opening
se = strel('disk', 2);
cleanedEdges = imopen(edges, se);
figure();
imshow(edges);
% Remove edges shorter than 50 pixels
minLength = 100;
BW_filtered = bwareaopen(edges, minLength);
figure();
imshow(BW_filtered);

请先登录,再进行评论。

更多回答(1 个)

To effectively detect edges in noisy images, it's important to undertake several pre-processing steps before applying an edge-detection algorithm. If your image contains significant noise, you can mitigate this by smoothing the image with a Gaussian filter, followed by a histogram equalization operation. This will yield a more refined image. You can then apply an edge detection algorithm.
Here's a code example illustrating the process:
BW = rgb2gray(X); % converting the image X to grayscale
B = imgaussfilt(BW,5); % applying a gaussian filter with standard deviation of 5 to the image
BW = histeq(B); % performing histogram equilization
BW1 = edge(BW,'canny'); % applying edge detector
imshow(BW1)
Feel free to experiment with the Gaussian filter's standard deviation and the choice of edge detection algorithm to optimize your results.
You can expect the final output to resemble the image shown below:
Please refer to the links below for the official documentation on the different functions:
Hope this helps.

2 个评论

Thank you! I am guessing the increasing the gaussian filter SD will errode the boundry of my cylinder right? As I am really interested in the dimensions I guess I shouldn't do this too strongly...
Hi @Tom Lancaster,
As for your concern, increasing the Gaussian filter's standard deviation may indeed erode the boundaries of your cylinder, so it is advisable to use a moderate value to maintain the integrity of the dimensions you are interested in.

请先登录,再进行评论。

产品

版本

R2024a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by