how to remove some regions from the image

조회 수: 4 (최근 30일)
vidya
vidya 2014년 2월 27일
편집: Image Analyst 2014년 2월 27일
good day all, my objective is to extract optic disc from the image..when i try to extract it i get some unwanted regions..is it possible or is there any method to remove unwaneted regions from the image . in the image below i want all white regions to be eliminated...inside white region there is a black color round shaped region, that is my optic disc and i want only that black part to remain

답변 (3개)

Image Analyst
Image Analyst 2014년 2월 27일
편집: Image Analyst 2014년 2월 27일
Try this code:
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 = 18;
% Read in a standard MATLAB gray scale demo image.
folder = 'D:\Temporary stuff';
baseFileName = 'optic.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.
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.
% numberOfColorBands should be = 1.
[rows, columns, numberOfColorBands] = size(grayImage);
if numberOfColorBands > 1
% It's not really gray scale like we expected - it's color.
% Convert it to gray scale by taking only the green channel.
grayImage = grayImage(:, :, 2); % Take green channel.
end
% Display the original gray scale image.
subplot(2, 2, 1);
imshow(grayImage, []);
axis on;
title('Original Grayscale 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')
% Binarize, invert, and clear border.
binaryImage = (grayImage < 128);
binaryImage = imclearborder(binaryImage);
subplot(2, 2, 2);
imshow(binaryImage, []);
title('Initial Binary Image', 'FontSize', fontSize);
axis on;
% Measure sizes
labeledImage = bwlabel(binaryImage);
measurements = regionprops(labeledImage, 'Area');
allAreas = [measurements.Area];
[biggestArea, indexOfBiggest] = sort(allAreas, 'descend')
% Extract largest
biggestBlob = ismember(labeledImage, indexOfBiggest(1));
% Convert to binary
biggestBlob = biggestBlob > 0;
subplot(2, 2, 3);
imshow(biggestBlob, []);
title('Final Binary Image', 'FontSize', fontSize);
axis on;
  댓글 수: 2
vidya
vidya 2014년 2월 27일
sir ..it works fine only for this particular image ..rest of the image it does not remove the unwanted region ..i think its probably cause of threshold problem...ny other way
Image Analyst
Image Analyst 2014년 2월 27일
Everything I do is based on just the one image you supply. And if different images look different you may need a more robust algorithm. That's why I keep telling you to not waste time with some simplistic algorithm of your own, that may need an image-by-image tweaking, and see the more robust algorithms that were published here: http://iris.usc.edu/Vision-Notes/bibliography/contentsmedical.html#Medical%20Applications,%20CAT,%20MRI,%20Ultrasound,%20Heart%20Models,%20Brain%20Models in section 20.5.

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


Meshooo
Meshooo 2014년 2월 27일
You can solve it by labeling. Try this code:
I = imread('optic.jpg');
%
bw = im2bw(I); % make it binary
bw = ~bw;
imshow(bw)
L = bwlabel(bw);
% Show the object labeled first.
imshow(L == 23) % your targeted object was number 23
Hope that solves your problem..

Dishant Arora
Dishant Arora 2014년 2월 27일
Why not mask out region of interest using imfreehand.
h = imfreehand(gca);
wait(h) % waits for user to specify region of interest
bw = createMask(h) % Binary mask with 1's inside ROI

카테고리

Help CenterFile Exchange에서 Convert Image Type에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by