To remove white backgroud you need to follow this:
%=============================================================================== baseFileName = 'concrete_inverted.png'; folder = []; % Determine where demo folder is (works with all versions). fullFileName = fullfile(folder, baseFileName); %=============================================================================== grayImage = imread(fullFileName); [rows, columns, numberOfColorChannels] = size(grayImage) if numberOfColorChannels > 1 grayImage = rgb2gray(grayImage); end % Display the image. subplot(2, 2, 1); imshow(grayImage, []); axis on; axis image; caption = sprintf('Original Gray Scale Image'); title(caption, 'FontSize', fontSize, 'Interpreter', 'None'); drawnow; hp = impixelinfo(); set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]); set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off') drawnow; mask = grayImage > 128; mask(1:2, :) = false; subplot(2, 2, 2); imshow(mask); axis on; axis image; title('Binary Image Mask', 'fontSize', fontSize); drawnow; % Get rid of small blobs. mask = bwareaopen(mask, 500); % Label the image. labeledImage = bwlabel(mask); % Find the areas and perimeters props = regionprops(labeledImage, 'Area', 'Perimeter'); allAreas = [props.Area]; sortedAreas = sort(allAreas, 'descend') allPerimeters = [props.Perimeter]; % Compute circularities circularities = allPerimeters .^ 2 ./ (4 * pi * allAreas) sortedC = sort(circularities, 'descend') % Keep conly blobs that are nowhere close to circular or compact. minAllowableCircularity = 10; keeperIndexes = find(circularities >= minAllowableCircularity); mask = ismember(labeledImage, keeperIndexes); % Display the mask image. subplot(2, 2, 3); imshow(mask); axis on; axis image; % Make sure image is not artificially stretched because of screen's aspect ratio. title('Intermediate Cleaned Mask', 'FontSize', fontSize); drawnow; % Get rid of black islands (holes) in struts without filling large black areas. subplot(2, 2, 4); mask = ~bwareaopen(~mask, 1000); imshow(mask); axis on; axis image; % Make sure image is not artificially stretched because of screen's aspect ratio. title('Final Cleaned Mask', 'FontSize', fontSize); drawnow;
Matlabsolutions.com provides guaranteed satisfaction with a
commitment to complete the work within time. Combined with our meticulous work ethics and extensive domain
experience, We are the ideal partner for all your homework/assignment needs. We pledge to provide 24*7 support
to dissolve all your academic doubts. We are composed of 300+ esteemed Matlab and other experts who have been
empanelled after extensive research and quality check.
Matlabsolutions.com provides undivided attention to each Matlab
assignment order with a methodical approach to solution. Our network span is not restricted to US, UK and Australia rather extends to countries like Singapore, Canada and UAE. Our Matlab assignment help services
include Image Processing Assignments, Electrical Engineering Assignments, Matlab homework help, Matlab Research Paper help, Matlab Simulink help. Get your work
done at the best price in industry.