How to remove black (no perfectly black) background and calculate area of cracks?
Dear all,
I’m trying to remove the background (not perfectly black) from the attached image. I have tried many methods, including setting thresholds and visualizing the data with the attached code. However, I realized that this might not be the best approach for this image because it also removes information within the circle (tomography of a cylindrical sample). I believe the best way would be to define a mask with the radius of the circle, but I don’t know how to determine it. Can anyone help fix the issues in my code or define a new one for the circular mask? The final aim is to calculate the area of the cracks.
I really appreciate any help!
clear all
close all
clc
I= imread(‘image_1567.png’);
FG = fliplr(imadjust(I,[0.05 1]));
sout = size(I);
squaresize = [10 10];
xx = mod(0:(sout(2)-1),squaresize(2)*2)<squaresize(2);
yy = mod(0:(sout(1)-1),squaresize(1)*2)<squaresize(1);
BG = im2uint8(0.3 + bsxfun(@xor,xx,yy’)*0.4);
mask = FG>10;
outpict = BG;
outpict(mask) = FG(mask);
outpict = uint8(double(FG).*mask + double(BG).*(1-mask));
subplot(3,2,1);
imshow(I,[]);
title(‘Original Grayscale Image’, ‘FontSize’, 15);
subplot(3,2,2);
imhist(I);
title(‘Histogram of original image’);
subplot(3,2,3);
imhist(outpict);
[counts, grayLevels] = imhist(outpict);
bar(grayLevels, counts, ‘EdgeColor’, ‘r’, ‘FaceColor’, ‘b’, ‘BarWidth’, 1);
xlim([0, max(outpict(:))]);
title(‘Histogram of output image with threshold 60’);
subplot(3,2,4);
thresholdValue1 = 60;
f.InvertHardcopy = ‘off’;
binaryImage1 = outpict > thresholdValue1;
imshow(binaryImage1, []);
title(‘Binary Image threshold 60’);
f.InvertHardcopy = ‘off’;
figure (1)Dear all,
I’m trying to remove the background (not perfectly black) from the attached image. I have tried many methods, including setting thresholds and visualizing the data with the attached code. However, I realized that this might not be the best approach for this image because it also removes information within the circle (tomography of a cylindrical sample). I believe the best way would be to define a mask with the radius of the circle, but I don’t know how to determine it. Can anyone help fix the issues in my code or define a new one for the circular mask? The final aim is to calculate the area of the cracks.
I really appreciate any help!
clear all
close all
clc
I= imread(‘image_1567.png’);
FG = fliplr(imadjust(I,[0.05 1]));
sout = size(I);
squaresize = [10 10];
xx = mod(0:(sout(2)-1),squaresize(2)*2)<squaresize(2);
yy = mod(0:(sout(1)-1),squaresize(1)*2)<squaresize(1);
BG = im2uint8(0.3 + bsxfun(@xor,xx,yy’)*0.4);
mask = FG>10;
outpict = BG;
outpict(mask) = FG(mask);
outpict = uint8(double(FG).*mask + double(BG).*(1-mask));
subplot(3,2,1);
imshow(I,[]);
title(‘Original Grayscale Image’, ‘FontSize’, 15);
subplot(3,2,2);
imhist(I);
title(‘Histogram of original image’);
subplot(3,2,3);
imhist(outpict);
[counts, grayLevels] = imhist(outpict);
bar(grayLevels, counts, ‘EdgeColor’, ‘r’, ‘FaceColor’, ‘b’, ‘BarWidth’, 1);
xlim([0, max(outpict(:))]);
title(‘Histogram of output image with threshold 60’);
subplot(3,2,4);
thresholdValue1 = 60;
f.InvertHardcopy = ‘off’;
binaryImage1 = outpict > thresholdValue1;
imshow(binaryImage1, []);
title(‘Binary Image threshold 60’);
f.InvertHardcopy = ‘off’;
figure (1) Dear all,
I’m trying to remove the background (not perfectly black) from the attached image. I have tried many methods, including setting thresholds and visualizing the data with the attached code. However, I realized that this might not be the best approach for this image because it also removes information within the circle (tomography of a cylindrical sample). I believe the best way would be to define a mask with the radius of the circle, but I don’t know how to determine it. Can anyone help fix the issues in my code or define a new one for the circular mask? The final aim is to calculate the area of the cracks.
I really appreciate any help!
clear all
close all
clc
I= imread(‘image_1567.png’);
FG = fliplr(imadjust(I,[0.05 1]));
sout = size(I);
squaresize = [10 10];
xx = mod(0:(sout(2)-1),squaresize(2)*2)<squaresize(2);
yy = mod(0:(sout(1)-1),squaresize(1)*2)<squaresize(1);
BG = im2uint8(0.3 + bsxfun(@xor,xx,yy’)*0.4);
mask = FG>10;
outpict = BG;
outpict(mask) = FG(mask);
outpict = uint8(double(FG).*mask + double(BG).*(1-mask));
subplot(3,2,1);
imshow(I,[]);
title(‘Original Grayscale Image’, ‘FontSize’, 15);
subplot(3,2,2);
imhist(I);
title(‘Histogram of original image’);
subplot(3,2,3);
imhist(outpict);
[counts, grayLevels] = imhist(outpict);
bar(grayLevels, counts, ‘EdgeColor’, ‘r’, ‘FaceColor’, ‘b’, ‘BarWidth’, 1);
xlim([0, max(outpict(:))]);
title(‘Histogram of output image with threshold 60’);
subplot(3,2,4);
thresholdValue1 = 60;
f.InvertHardcopy = ‘off’;
binaryImage1 = outpict > thresholdValue1;
imshow(binaryImage1, []);
title(‘Binary Image threshold 60’);
f.InvertHardcopy = ‘off’;
figure (1) image segmentation, imshow, imhist, background, image analysis MATLAB Answers — New Questions