how to identify high-intensity pixel ?

Can anyone help me to identify high-intensity regions for segmenting the tumor( image of the brain as the following figure)

Answers (1)

Image Analyst
Image Analyst on 4 Oct 2017
Edited: Image Analyst on 4 Oct 2017

28 Comments

I tried with your code, but it shows me the following error: Undefined function 'bwareafilt' for input arguments of type 'double'. Error in bl2 (line 152) binaryTumorImage = bwareafilt(binaryImage, 1);
You have an old version of MATLAB. Just replace the line with something like
binaryTumorImage = bwareaopen(binaryImage, 100);
This will possibly get you multiple blobs though, instead of just one. However you can increase the second argument to make it big enough so that only your largest blob gets extracted.
thanks, please tell me what is called the method you used in the step of extracting the skull
You can call it "skull stripping" overall. It uses "thresholding" as one of the main steps of it.
please can you give me the the explanation of the part " find tumor boundaries ", really I want in my work.
At that point in the code, there is already a binary image that says where the tumor is and isn't. That part of the code simply calls bwboundaries() to get a list of (x,y) coordinates of the outer perimeter of the binary blob that indicates the tumor.
for the part (Threshold the image) , if we change the image we must also change the threshold value, can you give me a solution where we don't need to change each time the threshold value.
Sorry, no. If the image changes, you must compute a new threshold value, and you must come up with an algorithm for that, or you can do it interactively using my visual thresholding app: http://www.mathworks.com/matlabcentral/fileexchange/29372-thresholding-an-image
can you help me, which function allows to calculate the low and the high value of the threshold (histogram)
like the following histogram
Well one way might be to zero out the counts from 0 to 50 or so. Then find the highest peak. Then find the lowest point from that peak to the right side. Like
counts(1:50) = 0;
[maxValue, indexOfMax] = max(counts);
counts(1:indexOfMax) = maxValue;
[minValue, threshold] = min(counts);
Image Analyst
Image Analyst on 17 Oct 2017
Edited: Image Analyst on 17 Oct 2017
What is "exuction"?
DON'T name your function hist. There is a built in function by that name that you should not destroy.
please can you help me, I need in my work
Try this:
clc; % Clear command window.
clear; % Delete all variables.
close all; % Close all figure windows except those created by imtool.
imtool close all; % Close all figure windows created by imtool.
workspace; % Make sure the workspace panel is showing.
fontSize = 25;
grayImage=imread('2.jpg');
% 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(2,2,1);
imshow(grayImage);
title('Original Gray Scale Image', 'FontSize', fontSize);
% Display the histogram so we can see what gray level we need to threshold it at.
subplot(2,2,3:4);
hObj = histogram(grayImage, 256)
grid on;
title('Histogram', 'FontSize', fontSize, 'Interpreter', 'None')
% Find threshold.
counts = hObj.Values;
counts(1:50) = 0;
[maxValue, indexOfMax] = max(counts);
counts(1:indexOfMax) = maxValue;
[minValue, threshold] = min(counts)
hold on;
line([threshold, threshold], ylim, 'Color', 'r', 'LineWidth', 2);
xticks(0:20:255);
% Binarize image
binaryImage = grayImage > threshold;
subplot(2,2,2);
imshow(binaryImage);
title('Binary Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0.04, 1, 0.96]);
thank you, it displays the high and low threshold value, just it displays the following error: How to correct it please :
Undefined function or variable 'xticks'.
Error in newhist (line 36)
xticks(0:20:255);
Just remove that line completely, or else upgrade your MATLAB. It came along in a newer version of MATLAB than you have.
I use Matlab R2015a and thank you. you help me a lot
Threshold the skullFreeImage instead of the original gray scale image. Then use the mask to erase everything from the image except the tumor.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures if you have the Image Processing Toolbox.
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
grayImage=imread('2.jpg');
[rows, columns, numberOfColorChannels] = size(grayImage);
if numberOfColorChannels > 1
grayImage = rgb2gray(grayImage);
end
%%%%%%%%%%
subplot(2,3,1);
imshow(grayImage);
title('Original Grayscale Image', 'FontSize', fontSize);
% Display the histogram so we can see what gray level we need to threshold it at.
subplot(2, 3, 2:3);
hObj = histogram(grayImage, 256)
grid on;
title('Histogram', 'FontSize', fontSize, 'Interpreter', 'None')
% Find threshold.
counts = hObj.Values;
counts(1:50) = 0;
[maxValue, indexOfMax] = max(counts);
counts(1:indexOfMax) = maxValue;
[minValue, threshold] = min(counts)
hold on;
line([threshold, threshold], ylim, 'Color', 'r', 'LineWidth', 2);
%xticks(0:20:255);
% Binarize image
binaryImage = grayImage > threshold;
subplot(2,3,4);
imshow(binaryImage);
title('Binary Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0.04, 1, 0.96]);
%%%%%%%%%%%
% Extract the outer blob, which is the skull.
% The outermost blob will have a label number of 1.
labeledImage = bwlabel(binaryImage); % Assign label ID numbers to all blobs.
binaryImage = ismember(labeledImage, 1); % Use ismember() to extract blob #1.
% Thicken it a little with imdilate().
binaryImage = imdilate(binaryImage, true(5));
% Display the final binary image.
subplot(2, 3, 5);
imshow(binaryImage, []);
axis on;
caption = sprintf('Extraction Skull ');
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
%%%%%%%%%%%
% Mask out the skull from the original gray scale image.
skullFreeImage = grayImage; % Initialize
skullFreeImage(binaryImage) = 0; % Mask out.
% Display the image.
subplot(2, 3, 6);
imshow(skullFreeImage, []);
axis on;
caption = sprintf('Gray Scale Image\nwith Skull Stripped Away');
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
%%%%%%%%%%%
% Give user a chance to see the results on this figure, then offer to continue and find the tumor.
promptMessage = sprintf('Do you want to continue and find the tumor,\nor Quit?');
titleBarCaption = 'Continue?';
buttonText = questdlg(promptMessage, titleBarCaption, 'Continue', 'Quit', 'Continue');
if strcmpi(buttonText, 'Quit')
return;
end
% Now threshold to find the tumor
binaryImage = skullFreeImage > threshold;
% Display the image.
hFig2 = figure();
subplot(2, 2, 1);
imshow(binaryImage, []);
axis on;
caption = sprintf('Initial Binary Image\nThresholded at %d Gray Levels', threshold);
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
%%%%%%%%%%%
% Assume the tumor is the largest blob, so extract it
%binaryTumorImage = bwareafilt(binaryImage, 1);
binaryTumorImage = bwareaopen(binaryImage, 100);
% Display the image.
subplot(2, 2, 2);
imshow(binaryTumorImage, []);
axis on;
caption = sprintf('Tumor Alone (binary mask)');
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
%%%%%%%%%%%
% Find tumor boundaries.
% bwboundaries() returns a cell array, where each cell contains the row/column coordinates for an object in the image.
% Plot the borders of the tumor over the original grayscale image using the coordinates returned by bwboundaries.
subplot(2, 2, 3);
imshow(grayImage, []);
axis on;
caption = sprintf('Tumor\nOutlined in red in the overlay');
title(caption, 'FontSize', fontSize,'Interpreter', 'None');
axis image; % Make sure image is not artificially stretched because of screen's aspect ratio.
hold on;
boundaries = bwboundaries(binaryTumorImage);
numberOfBoundaries = size(boundaries, 1);
for k = 1 : numberOfBoundaries
thisBoundary = boundaries{k};
% Note: since array is row, column not x,y to get the x you need to use the second column of thisBoundary.
plot(thisBoundary(:,2), thisBoundary(:,1), 'r', 'LineWidth', 2);
end
hold off;
% Extract the gray scale tumors alone
tumorOnlyImage = grayImage; % Initialize
% Erase everything except the tumors
tumorOnlyImage(~binaryTumorImage) = 0;
subplot(2, 2, 4);
imshow(tumorOnlyImage, []);
axis on;
caption = sprintf('Tumor only (gray scale image)');
title(caption, 'FontSize', fontSize,'Interpreter', 'None');
axis image; % Make sure image is not artificially stretched because of screen's aspect ratio.
please can you suggest me another example for the segmentation of brain lesions
No - I think this should be enough. Why do you need one? You can adapt this to make your own custom example if you want.
If you want more sophisticated algorithms, see VisionBib or PubMed.
thanks, I am looking for another method (uncomplicated) just to do a comparative study
Well good luck. It generally can't get any more uncomplicated than thresholding. Please take the time to understand each step and then it won't seem so complicated.
I applied the thresholding method on another image but it does not give a good result !! Can you help me
Like I said, if thresholding is too complicated for you, then more robust and accurate methods (that I gave you in the VisionBib or PubMed links) will be WAY too complicated for you. I suggest you hire someone to do it.
the thresholding is not complicated but unfortunately it does not give a good result with other images
That's why you need to use more sophisticated, and complicated, algorithms.
Yes, it's true

Sign in to comment.

Asked:

on 4 Oct 2017

Commented:

on 2 Dec 2017

Community Treasure Hunt

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

Start Hunting!