You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
how to identify high-intensity pixel ?
4 views (last 30 days)
Show older comments
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
on 4 Oct 2017
Edited: Image Analyst
on 4 Oct 2017
Try thresholding. See attached demo.
Also see my Image Segmentation Tutorial: http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862&sort=downloads_desc
28 Comments
Image Analyst
on 5 Oct 2017
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.
Image Analyst
on 12 Oct 2017
You can call it "skull stripping" overall. It uses "thresholding" as one of the main steps of it.
Image Analyst
on 15 Oct 2017
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.
Image Analyst
on 16 Oct 2017
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
Image Analyst
on 16 Oct 2017
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
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.
Image Analyst
on 18 Oct 2017
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]);
Image Analyst
on 18 Oct 2017
Just remove that line completely, or else upgrade your MATLAB. It came along in a newer version of MATLAB than you have.
Image Analyst
on 31 Oct 2017
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.
Image Analyst
on 22 Nov 2017
Image Analyst
on 22 Nov 2017
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.
Image Analyst
on 2 Dec 2017
Image Analyst
on 2 Dec 2017
That's why you need to use more sophisticated, and complicated, algorithms.
See Also
Categories
Find more on Display Image in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)