Hello everyone , how can i remove the noise in the image without having effect on my RIO?

2 views (last 30 days)
washere
washere on 18 Dec 2021
Answered: Image Analyst on 18 Dec 2021
  1 Comment
Walter Roberson
Walter Roberson on 18 Dec 2021
~bwareafilt(~YourImage, [THRESHOLD inf])
THRESHOLD should be the area of the smallest black blob to keep.
I estimate that the largest of the black streaks might have area close to the area of the top lobe of the 8, so you might not be able to get perfect filtering this way.

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 18 Dec 2021
See attached:
% Demo by Image Analyst
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 14;
markerSize = 40;
%--------------------------------------------------------------------------------------------------------
% READ IN IMAGE
fileName = 'image.jpeg';
grayImage = imread(fileName);
% Get the dimensions of the image.
% numberOfColorChannels should be = 1 for a gray scale image, and 3 for an RGB color image.
[rows, columns, numberOfColorChannels] = size(grayImage)
if numberOfColorChannels > 1
% It's not really gray scale like we expected - it's color.
% Extract the blue channel.
grayImage = grayImage(:, :, 3);
end
%--------------------------------------------------------------------------------------------------------
% Display the image.
subplot(3, 1, 1);
imshow(grayImage);
impixelinfo;
axis('on', 'image');
title('Original Gray Scale Image', 'FontSize', fontSize, 'Interpreter', 'None');
hold on
drawnow;
% Maximize window.
g = gcf;
g.WindowState = 'maximized'
drawnow;
%--------------------------------------------------------------------------------------------------------
% Get a mask using thresholding.
maskOriginal = grayImage < 128;
% Fill holes
mask = imfill(maskOriginal, 'holes');
% Get convex hull
mask = bwconvhull(mask, 'objects');
% Take the largest blob.
mask = bwareafilt(mask, 1);
% Display the image.
subplot(3, 1, 2);
imshow(mask, []);
impixelinfo;
axis('on', 'image');
title('Mask/Binary/Logical Image', 'FontSize', fontSize, 'Interpreter', 'None');
hold on
drawnow;
% Apply the mask to the original image.
mask = mask & ~maskOriginal;
% We know/expect there to be 6 numbers so extract the 6 largest blobs.
mask = bwareafilt(mask, 6);
% A blob is hanging on to one of the numbers by a thin thread.
% Find this thread and break it by erasing below it.
verticalProfile = sum(mask, 2);
subplot(3, 1, 3);
plot(verticalProfile, 'b-', 'LineWidth', 2)
% Find lines where there are less than 10 pixels and erase them.
badLines = verticalProfile <= 10;
mask(badLines, :) = false;
% Find centroid of remaining blobs
mask2 = bwconvhull(mask, 'objects');
% Label the image.
[L, numBlobs] = bwlabel(mask2);
props = regionprops(L, 'Centroid');
xyCentroids = vertcat(props.Centroid);
yCentroids = xyCentroids(:, 2);
% Find outliers
outlierIndexes = isoutlier(yCentroids);
keepers = 1 : numBlobs;
keepers(outlierIndexes) = []; % Don't keep numbers whose centroid is not on the line.
mask2 = ismember(L, keepers);
% AND it with the original mask to erase the outliers.
mask = mask & mask2;
% Display the image.
subplot(3, 1, 3);
imshow(mask, []);
impixelinfo;
axis('on', 'image');
title('Final Mask', 'FontSize', fontSize, 'Interpreter', 'None');
hold on
drawnow;
% Do OCR on it.
txt = ocr(mask)
letters = strtrim(txt.Text)
caption = sprintf('Mask/Binary/Logical Image. Text = %s', letters);
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');

More Answers (1)

DGM
DGM on 18 Dec 2021
Edited: DGM on 18 Dec 2021
Here's a start. There's more that could be done, but don't assume this is universally applicable.
A = rgb2gray(imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/837960/image.jpeg'))>128;
% create a mask which includes the plate and all of its interior blobs
platemask = imdilate(bwareafilt(~A,1),strel('disk',5));
platemask = imfill(platemask,'holes');
% apply the mask; get rid of any specks caught by the mask edges
B = ~bwareaopen(~A & platemask,50);
imshow(B)

Community Treasure Hunt

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

Start Hunting!