how to identify high-intensity pixel ?
4 次查看(过去 30 天)
显示 更早的评论
marwa za
2017-10-4
Can anyone help me to identify high-intensity regions for segmenting the tumor( image of the brain as the following figure)
回答(1 个)
Image Analyst
2017-10-4
编辑:Image Analyst
2017-10-4
Try thresholding. See attached demo.
Also see my Image Segmentation Tutorial: http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862&sort=downloads_desc
28 个评论
marwa za
2017-10-4
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);
Image Analyst
2017-10-5
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.
marwa za
2017-10-12
thanks, please tell me what is called the method you used in the step of extracting the skull
Image Analyst
2017-10-12
You can call it "skull stripping" overall. It uses "thresholding" as one of the main steps of it.
marwa za
2017-10-15
please can you give me the the explanation of the part " find tumor boundaries ", really I want in my work.
Image Analyst
2017-10-15
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.
marwa za
2017-10-16
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.
Image Analyst
2017-10-16
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
marwa za
2017-10-16
can you help me, which function allows to calculate the low and the high value of the threshold (histogram)
like the following histogram
Image Analyst
2017-10-16
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
2017-10-17
编辑:Image Analyst
2017-10-17
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
2017-10-18
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]);
marwa za
2017-10-18
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);
Image Analyst
2017-10-18
Just remove that line completely, or else upgrade your MATLAB. It came along in a newer version of MATLAB than you have.
Image Analyst
2017-10-31
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
2017-11-22
marwa za
2017-11-22
thanks, I am looking for another method (uncomplicated) just to do a comparative study
Image Analyst
2017-11-22
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.
marwa za
2017-12-1
I applied the thresholding method on another image but it does not give a good result !! Can you help me
Image Analyst
2017-12-2
marwa za
2017-12-2
the thresholding is not complicated but unfortunately it does not give a good result with other images
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!发生错误
由于页面发生更改,无法完成操作。请重新加载页面以查看其更新后的状态。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- 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)
亚太
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)