How to remove light artifact in this image? After removing this light artifact the blood vessels should look same in the region in light artifact region. Any code for this ?
4 次查看(过去 30 天)
显示 更早的评论
3 个评论
Adam Danz
2020-1-20
To add to Image Analyst's point, you can see two retinal blood vessels to the right of the light artifact but only one extends to the left. Even if the vessels were interpolated across the section of missing data, there's no way of knowing which vessel is the one extending across the region of missing data.
Adam Danz
2020-1-21
Pulkit NCU's answer moved here as a comment.
Ok fine. I want only the light artifact region and other region of fundus image should become black. Any code that select only the bright region i.e. intensity > 250 and selects it and other less than it make it black. Code for this for large dataset?
回答(2 个)
Adam Danz
2020-1-21
"I want only the light artifact region and other region of fundus image should become black... i.e. intensity > 250"
file = 'IM2794EY.jpeg'; % Using the full path is better
% Read image as grayscale
I = imread(file);
% Replace intensity values greater than 250 with 1
I(I > 250) = 1;
% Alternatively, you could replace those values with the average intensity.
% I(I > 250) = mean(I(I>1));
imshow(I)
0 个评论
Image Analyst
2020-1-21
"I want only the light artifact region and other region of fundus image should become black... i.e. intensity > 250"
So simply do this
binaryImage = binaryImage > 250;
Here is a full demo showing how to get the binary image (mask) and how to mask the original image to get an image with just pixels inside or outside the mask with everything else blackened.
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 = 22;
%===============================================================================
% Read in demo image.
folder = pwd;
baseFileName = 'IM2794EY.jpeg';
% 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);
% Display the image.
hFig = figure;
subplot(2, 2, 1);
imshow(grayImage, []);
title('Original Gray Scale Image', 'FontSize', fontSize, 'Interpreter', 'None');
axis('on', 'image');
hp = impixelinfo();
hFig.WindowState = 'maximized'; % May not work in earlier versions of MATLAB.
% 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(rgbImage);
% 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.
else
grayImage = grayImage; % It's already gray scale.
end
% Now it's gray scale with range of 0 to 255.
% Need to convert it into a logical (binary) image.
binaryImage = grayImage > 250;
% Take blobs only if they're larger than 30 pixels.
binaryImage = bwareaopen(binaryImage, 30);
% Fill any holes.
binaryImage = imfill(binaryImage, 'holes');
% Optional: find the areas of the blobs:
props = regionprops(binaryImage, 'Area');
allAreas = [props.Area]
% Display the image.
subplot(2, 2, 2);
imshow(binaryImage, []);
title('Binary Image (Mask)', 'FontSize', fontSize, 'Interpreter', 'None');
axis('on', 'image');
hp = impixelinfo();
% Create a gray scale masked image of the light areas only.
maskedGrayLight = grayImage; % Initialize.
maskedGrayLight(~binaryImage) = 0;
% Display the image.
subplot(2, 2, 3);
imshow(binaryImage, []);
title('Masked Grayscale Image Showing Light Parts of Image', 'FontSize', fontSize, 'Interpreter', 'None');
axis('on', 'image');
hp = impixelinfo();
% Create a gray scale masked image of the darker areas only.
maskedGrayDark = grayImage; % Initialize.
maskedGrayDark(binaryImage) = 0;
% Display the image.
subplot(2, 2, 4);
imshow(maskedGrayDark, []);
title('Masked Grayscale Image Showing Dark Parts of Image', 'FontSize', fontSize, 'Interpreter', 'None');
axis('on', 'image');
hp = impixelinfo();
%------------------------------------------------------------------------------
% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0.04, 1, 0.96]);
% Get rid of tool bar and pulldown menus that are along top of figure.
% set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
drawnow;
1 个评论
Adam Danz
2020-1-21
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!