Weird output image after applying mask
Show older comments
Hello.
So I'm doing some edge detection and want to apply it only to a specific region of interest (ROI). At first everything worked and you could draw a ROI with the mouse and a mask applied a canny filter on the selected bit, detect circles and cut out the rest of the picture.
For some reason the image with the mask applied started showing glitch like artifacts as seen in the picture below.

On the right is the picture with a Gauss-filter and on the left you can see the cut out area in the middle, which is the freehand-ROI, and on the left of it you can see the weird artifacts. The code also detects circles in the wrong spots, on some pictures it detects circles where there is nothing.
Thank you for any answers!
My code:
k2=imread("b3.jpg");
t1 =0.26; %sliders for thresholds and standard deviation for Gaussfiltering
t2 =0.09;
s = 4.98;
method1 = "canny"; %drop down menu of filters including sobel, prewitt etc.
% method2 = "canny";
k=rgb2gray(k2);
k=imgaussfilt(k,s);
% k=imsharpen(k);
% % imboxfilt(k);
% % imshow(k)
% % BW=edge(k, method1);
% BW=edge(k,"canny",[t2 t1]);
imshow(k)
hax = drawfreehand(gca);
mask = createMask(hax);
% f = @(x)edge(k,method2);
g = @(x)edge(k, method1, [t2 t1]);
% res = roifilt2(k, mask, f);
res = roifilt2(k, mask, g);
figure;
imshowpair(res,k,"Montage")
n=1;
[centers, radii, metric] = imfindcircles(schritt2,[10 1000]);
coords=centers(1:n,:);
rad=radii(1:n);
met=metric(1:n);
viscircles(coords, rad, "EdgeColor",'b');
Accepted Answer
More Answers (0)
Categories
Find more on ROI-Based Processing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!