how can i detect the ROI from the Image ?

ROI is Tumor in the MRI. I want to extract the roi alone and have to display it?

4 Commenti

Is it possible to use FCM method to seperate the ROI?
It looks like the tumor already has a unique value. What have you tried already?
@sam CP and Cedric pton: I do not understand the reason to set flags. The posted image does not allow to recognize the person. It does not contain any comments, no date of birth e.g. The code does not contain "private" details also.
Therefore I've removed both flags. But if you see a real problem, please explain this in detail or ask the admins to clean this thread thread (follow the "Contact us" button and add a link to this thread). Thanks.
Hi Sam CP, Did you find an answer for your question? I want to extract the ROI voxel values.

Accedi per commentare.

 Risposta accettata

Try this.
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 = 15;
%===============================================================================
% Get the name of the image the user wants to use.
baseFileName = 'tumor.jpg'; % Assign the one on the button that they clicked on.
% Get the full filename, with path prepended.
folder = []; % Determine where demo folder is (works with all versions).
fullFileName = fullfile(folder, baseFileName);
%===============================================================================
% Read in a demo image.
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(:, :, 2); % Take green channel.
end
% Display the image.
subplot(1, 2, 1);
imshow(grayImage, []);
axis on;
caption = sprintf('Original Gray Scale Image');
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
drawnow;
hp = impixelinfo();
% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% 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')
hold on;
drawnow;
% Threshold to get pixels in the range
tumor = (grayImage >= 155) & (grayImage < 189);
% Extract the largest blob;
tumor = bwareafilt(tumor, 1);
% Display the image.
subplot(1, 2, 2);
imshow(tumor, []);
axis on;
caption = sprintf('Tumor Image');
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
drawnow;
By the way, kmeans is not a good way to detect tumors.

6 Commenti

After kmeans i will get the following image
figure,
imshow(pixel_labels,[]), title('Kmeans clustering');
This image is input image to the above code. I have read the the image in the way you described in the above code
grayImage=pixel_labels;
But i get a blank image in the output as result.how can i correct it?
Examine its variables in the variable editor. They're most likely not zero but values that are more than 1 that when the labeled image, which is a double, is displayed anything in the range above 1 is displayed as white. Use [] to scale the image just for display
imshow(grayImage, []);
sam  CP
sam CP il 2 Apr 2017
Modificato: sam CP il 2 Apr 2017
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 = 15;
% Get the name of the image the user wants to use.
[filename pathname] = uigetfile({'*.jpg';'*.bmp'},'Select MRI');
inputimage=strcat(pathname, filename);
input=imread(inputimage);
% input=rgb2gray(imread(inputimage));
[m,n,p] = size(input) ;
if p==1
disp('Select RGB image')
end
% axes(handles.axes1)
figure,
imshow(input,[]);
axis off;
title('Input Image','fontsize',12,'fontname','Times New Roman','color','Black');
[row,col,cha] = size(input);
input_img = input;
if cha ==3
input = rgb2gray(input);
end
preim = medfilt2(input);
% axes(handles.axes2)
figure,
imshow(preim,[]);
axis off;
title('Preprocessed Image','fontsize',12,'fontname','Times New Roman','color','Black');
% step -Kmeans
I(:,:,1) = input_img(:,:,1);
I(:,:,2) = input_img(:,:,2);
I(:,:,3) = input_img(:,:,3);
% Hematoxylin and eosin
text(size(I,2),size(I,1)+15,...
'Clustering process is done', ...
'FontSize',7,'HorizontalAlignment','right');
ab = double(I(:,:,2:3));
nrows = size(ab,1);
ncols = size(ab,2);
ab = reshape(ab,nrows*ncols,2);
nColors = 4;
rng('default');
[cluster_idx, cluster_center] = kmeans(ab,nColors,'distance','sqEuclidean', ...
'Replicates',2);
pixel_labels = reshape(cluster_idx,nrows,ncols);
figure,
imshow(pixel_labels,[]), title('Kmeans clustering');
%===============================================================================
% Read in a demo image.
grayImage = pixel_labels;
% 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(:, :, 2); % Take green channel.
end
figure,
imshow(grayImage, []), title('Original Gray Scale Image');
% Threshold to get pixels in the range
tumor = (grayImage >= 155) & (grayImage < 189);
% Extract the largest blob;
tumorseg = bwareafilt(tumor, 1);
tumor = imfill(tumorseg,'holes');
% Display the image.
figure,
imshow(tumor, []), title('Tumor Image');
imshow(tumor, []), title('Tumor Image'); will output a blank image
That's because in this line
tumor = (grayImage >= 155) & (grayImage < 189);
the thresholds are wrong. When I run your code on the image you gave me, the tumor is a different brightness than before and not in the range I specified. You can't run kmeans (which I already said was a bad method) on the output of an image that has already BEEN classified with kmeans! That's like doing it twice, so it's twice as bad. My code was meant to be run on the image after it had been through kmeans and had the gray levels you originally had in the image you posted. You can't just stick a kmeans after reading in a kmeans classified image and before my code. That makes no sense. If you want me to run it again, you'll have to post the original gray scale image, not a screenshot of a kmeans classified image.
This is original gray scale image.
There are SO many problems with that it will take me a while to fix it. Like using an RGB image, using "input" as the name of a variable, computing the median filtered image but never using it, and so on.

Accedi per commentare.

Più risposte (1)

Sam, another problem I found in your code was that you did not realize that kmeans can produce a different cluster index for the tumor each time you run it. So I had to figure out what label it was at and then extract that. Here is the corrected 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 = 15;
% Get the name of the image the user wants to use.
folder = pwd;
filename = 'brain2.jpg';
% [filename, folder] = uigetfile({'*.jpg';'*.bmp'},'Select MRI');
inputimage = fullfile(folder, filename);
inputImage = imread(inputimage);
% Display the image
subplot(2, 2, 1);
imshow(inputImage,[]);
axis on image;
title('Input Image','fontsize',fontSize);
% Convert to gray scale if needed.
[rows, columns, numberOfColorChannels] = size(inputImage);
if numberOfColorChannels == 3
fprintf('That was a color image. I am converting it to grayscale.\n');
inputImage = rgb2gray(inputImage);
end
% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% 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;
hp = impixelinfo(); % Set up status line to see values when you mouse over the image.
% Compute the median filtered image.
medianFilteredImage = medfilt2(inputImage);
subplot(2, 2, 2);
imshow(medianFilteredImage,[]);
axis on image;
title('Median Filtered Image','FontSize', fontSize);
hp = impixelinfo(); % Set up status line to see values when you mouse over the image.
% Define some number of clusters that you know will definitely be there.
numberOfClusters = 5;
% Do kmeans clustering on the median filtered image.
grayLevels = double(medianFilteredImage(:));
[clusterIndexes, clusterCenters] = kmeans(grayLevels, numberOfClusters,...
'distance', 'sqEuclidean', ...
'Replicates', 2);
labeledImage = reshape(clusterIndexes, rows, columns);
subplot(2, 2, 3);
imshow(labeledImage,[])
title('Kmeans Clustering','FontSize', fontSize);
axis on image;
% colorbar
hp = impixelinfo(); % Set up status line to see values when you mouse over the image.
%===============================================================================
% Now kmeans can give a different index to the tumor in each run,
% so we'll assume the tumor is the brightest class.
% Find the brightest class.
[maxValue, indexOfMaxValue] = max(clusterCenters)
% Get pixels that are labeled as the tumor.
tumor = labeledImage == indexOfMaxValue;
% Extract the largest blob;
tumor = bwareafilt(tumor, 1);
% Fill holes.
tumor = imfill(tumor, 'holes');
% Display the image.
subplot(2, 2, 4);
imshow(tumor, []);
axis on image;
title('Tumor Binary Mask Image','FontSize', fontSize);
hp = impixelinfo(); % Set up status line to see values when you mouse over the image.
Again, I do not recommend this method as a good one for finding tumors. It's only use would be as a student exercise in how to use kmeans() on a 2-D array of values, not as an illustration of a good image segmentation method, because it's not.

9 Commenti

A more general demo (without median filtering but with pseudocoloring to distinguish blob labels) is attached.
Thank you ..
sam  CP
sam CP il 3 Apr 2017
Modificato: Image Analyst il 4 Apr 2017
I have worked on this.. And this method is not the efficient method. It shows problems when the ROI is very small or when ROI is didn't present in the image.
Sometimes the ROI will shows as dark, that time this thresholding can't be worked well.
I thought this can be give better result if the thresholding technique will be replaced by other methods.
Thresholding depends on there being a tumor that has a unique brightness range. If there is no tumor you don't want to find one. Also, if the range is not unique, like some normal tissue has that brightness, then it will find other non-tumor pixels, which you don't want. So thresholding, not matter how the threshold is determined (by cluster analysis or something else) might have to be supplemented with additional operations to make sure you get only true tumor pixels.
It will over segmented other parts of the MRI when i applied this thresholding method with some tumor images
What do you meant by that additional operations ? Is it for avoid the over segmentation.
Jan
Jan il 12 Ott 2017
Modificato: Jan il 12 Ott 2017
[MOVED from flag] abderrahim khatabi wrote:
Hello; i try your code to segmente the tumor but gave me this error: Undefined function 'bwareafilt' for input arguments of type 'double'. how can i slove this problem. thank you in advance.
@abderrahim khatabi; Please use flags only to inform editors and admins, that a contribution might conflict with the terms of use. Thanks.
bwareafilt() was only introduced in R2014b. You must have an earlier version so you should use bwareaopen() instead. See the documentation for how to use it.

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by