how can i detect the ROI from the Image ?
Mostra commenti meno recenti
ROI is Tumor in the MRI. I want to extract the roi alone and have to display it?
4 Commenti
sam CP
il 31 Mar 2017
Rik
il 31 Mar 2017
It looks like the tumor already has a unique value. What have you tried already?
Jan
il 3 Apr 2017
@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.
Hesham Alghodhaifi
il 13 Giu 2017
Hi Sam CP, Did you find an answer for your question? I want to extract the ROI voxel values.
Risposta accettata
Più risposte (1)
Image Analyst
il 2 Apr 2017
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
Image Analyst
il 2 Apr 2017
A more general demo (without median filtering but with pseudocoloring to distinguish blob labels) is attached.

sam CP
il 3 Apr 2017
sam CP
il 3 Apr 2017
Modificato: Image Analyst
il 4 Apr 2017
sam CP
il 4 Apr 2017
Image Analyst
il 4 Apr 2017
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.
sam CP
il 4 Apr 2017
sam CP
il 4 Apr 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.
Image Analyst
il 13 Ott 2017
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.
Categorie
Scopri di più su k-Means and k-Medoids Clustering in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!