MATLAB: How to remove noise

daleknoise

I have uploaded images:
Please tell how to remove the extra white regions, other than the text. I need only the text. Please help.

Best Answer

For what's it's worth, here is 10 minutes worth of a very simplistic attempt to isolate letters. It obviously misses some of the letters for the reasons I mentioned in my comments above. That could possibly be fixed to get some of the missing ones, at the expense of altering the shapes of the ones it got correctly on the first pass, or maybe you can avoid even that with an even more sophisticated algorithm.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures.
clear; % Erase all existing variables.
workspace; % Make sure the workspace panel is showing.
fontSize = 20;
% Read in demo image.
folder = 'C:\Users\Kash\Documents\Temporary';
baseFileName = 'jlGZw.jpg';
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~exist(fullFileName, 'file')
% File doesn't exist -- didn't find it there. Check the search path for it.
fullFileName = baseFileName; % No path this time.
if ~exist(fullFileName, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist in the search path folders.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
grayImage = imread(fullFileName);
% Get the dimensions of the image.
% numberOfColorBands should be = 1.
[rows columns numberOfColorBands] = size(grayImage)
% Display the original gray scale image.
subplot(2, 3, 1);
imshow(grayImage, []);
title('Original Color Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
% Give a name to the title bar.
set(gcf,'name','Demo by ImageAnalyst','numbertitle','off')
% Convert to gray scale image and threshold to get binary image.
binaryImage = rgb2gray(grayImage) > 100;
% Display the image.



subplot(2, 3, 2);
imshow(binaryImage, []);
title('Binary Image', 'FontSize', fontSize);
% Invert it.
binaryImage2 = ~binaryImage;
% Display the image.
subplot(2, 3, 3);
imshow(binaryImage2, []);
title('Inverted Binary Image', 'FontSize', fontSize);
% Border kill.
binaryImage3 = imclearborder(binaryImage2);
% Get rid of blobs smaller than 15.
binaryImage3 = bwareaopen(binaryImage3, 15);
% Display the image.
subplot(2, 3, 4);
imshow(binaryImage3, []);
title('Binary Image', 'FontSize', fontSize);
% Crop to bounding box.
verticalProfile = any(binaryImage3, 2);
horizontalProfile = any(binaryImage3, 1);
x1 = find(horizontalProfile, 1, 'first');
x2 = find(horizontalProfile, 1, 'last');
y1 = find(verticalProfile, 1, 'first');
y2 = find(verticalProfile, 1, 'last');
binaryImage4 = imcrop(binaryImage3, [x1, y1, x2-x1+1, y2-y1+1]);
% Display the image.
subplot(2, 3, 5);
imshow(binaryImage4, []);
title('Binary Image', 'FontSize', fontSize);
% Label each blob with 8-connectivity, so we can make measurements of it
[labeledImage numberOfBlobs] = bwlabel(binaryImage4, 8);
% Apply a variety of pseudo-colors to the regions.
coloredLabelsImage = label2rgb (labeledImage, 'hsv', 'k', 'shuffle');
% Display the pseudo-colored image.
imshow(coloredLabelsImage);
% Get all the blob properties.
blobMeasurements = regionprops(labeledImage, 'all');
allAreas = [blobMeasurements.Area]
title('Labeled Letters', 'FontSize', fontSize);
Related Question