How to remove the gray dots from the black holes from the following image?

조회 수: 3 (최근 30일)
Kartikeya Dixit
Kartikeya Dixit 2018년 8월 10일
편집: Kartikeya Dixit 2018년 8월 14일
I have tried weiner2 filter, medfilt2 and gaussian blur also but the results are not satisfactory.
  댓글 수: 1
KALYAN ACHARJYA
KALYAN ACHARJYA 2018년 8월 12일
Can you explain it more? If you remove the gray from the image, then image turn to complete black. Pls, share the code what you have tried so far.

댓글을 달려면 로그인하십시오.

답변 (1개)

Image Analyst
Image Analyst 2018년 8월 12일
Try this code that removes all blobs except for the largest one:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clearvars; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
folder = pwd;
baseFileName = 'ceramic_4_000.bmp';
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~exist(fullFileName, 'file')
% The file doesn't exist -- didn't find it there in that folder.
% Check the entire search path (other folders) for the file by stripping off the folder.
fullFileNameOnSearchPath = baseFileName; % No path this time.
if ~exist(fullFileNameOnSearchPath, '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.
% 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.
% Use weighted sum of ALL channels to create a gray scale image.
% grayImage = rgb2gray(grayImage);
% ALTERNATE METHOD: Convert it to gray scale by taking only the green channel,
% which in a typical snapshot will be the least noisy channel.
grayImage = grayImage(:, :, 1); % Take red channel.
end
% Display the image.
subplot(2, 3, 1);
imshow(grayImage, []);
title('Original Grayscale Image', 'FontSize', fontSize, 'Interpreter', 'None');
hp = impixelinfo;
axis('on', 'image'); % Make sure image is not artificially stretched because of screen's aspect ratio.
%------------------------------------------------------------------------------
% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0.04, 1, 0.96]);
drawnow;
% Turn into a binary image.
binaryImage = imbinarize(grayImage);
% Find all the blobs.
[labeledImage, numberOfRegions] = bwlabel(binaryImage);
fprintf('Found %d regions.\n',numberOfRegions);
% Display the binary image.
subplot(2, 3, 2);
% imhist(grayImage);
imshow(binaryImage, []);
caption = sprintf('Binary Image with %d Blobs', numberOfRegions);
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
hp = impixelinfo;
axis('on', 'image'); % Make sure image is not artificially stretched because of screen's aspect ratio.
% Let's assign each blob a different color to visually show the user the distinct blobs.
coloredLabels = label2rgb (labeledImage, 'hsv', 'k', 'shuffle'); % pseudo random color labels
% coloredLabels is an RGB image. We could have applied a colormap instead (but only with R2014b and later)
subplot(2, 3, 3);
imshow(coloredLabels);
axis('on', 'image'); % Make sure image is not artificially stretched because of screen's aspect ratio.
caption = sprintf('Pseudo colored labels, from label2rgb().\nBlobs are numbered from top to bottom, then from left to right.');
title(caption, 'FontSize', fontSize);
binaryImage1 = bwareafilt(binaryImage, 1);
% Display the binary image.
subplot(2, 3, 4);
imshow(binaryImage1, []);
title('Binary Image with Islands Removed', 'FontSize', fontSize, 'Interpreter', 'None');
hp = impixelinfo;
axis('on', 'image'); % Make sure image is not artificially stretched because of screen's aspect ratio.
% Get an image of just the small blobs
smallBlobs = binaryImage & ~binaryImage1;
% Display the binary image.
subplot(2, 3, 5);
imshow(smallBlobs, []);
title('Binary Image of Islands', 'FontSize', fontSize, 'Interpreter', 'None');
hp = impixelinfo;
axis('on', 'image'); % Make sure image is not artificially stretched because of screen's aspect ratio.
% Erase the small blobs by setting them to zero in the original gray image.
grayImage(smallBlobs) = 0;
% Display the final gray image with the small gray islands replaced.
subplot(2, 3, 6);
imshow(grayImage, []);
title('Gray Image with Islands Removed', 'FontSize', fontSize, 'Interpreter', 'None');
hp = impixelinfo;
axis('on', 'image'); % Make sure image is not artificially stretched because of screen's aspect ratio.
  댓글 수: 1
Image Analyst
Image Analyst 2018년 8월 13일
Well that's totally different than "remove the gray dots from the black holes". So why aren't you using medfilt2()?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by