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 remove the pectoral muscle from the mammogram?
2 views (last 30 days)
Show older comments
I used imclearborder() but it doesn’t work. Can anyone give me advice?! i want to remove the left part behind the red line
13 Comments
Image Analyst
on 10 Sep 2018
Why is there an intensity discontinuity in the top band of the image? Will all your images have that? Will all images have the pectoral muscle separated from the breast by a dark region, or will the breast be just as bright, and connected to, the pectoral region in some images?
Can you attach the original image, without the red annotation line?
Image Analyst
on 10 Sep 2018
And can you attach your code that you have so far? I doubt whatever I think of off the top of my head will be as robust as those methods that people have worked on for months and perfected.
Afaf Saad
on 10 Sep 2018
Edited: Afaf Saad
on 10 Sep 2018
yes, pectoral muscle removal is the second step i want to do because i want to train Convolution neural network with those images after getting ROI. i extracted the whole breast but i want to remove this part to improve the segmented images. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%555 clc;
close all
clear;
%load image from my directory
folder='C:\Users\afaf\Documents\MATLAB\all-mias\NormaL';
newfolder='C:\Users\afaf\Documents\MATLAB\all-mias\NormalRotated';
filepattern=fullfile(folder,'*.pgm');
myfiles=dir(filepattern);
se = strel('disk',15);
% read images and resize
for k=1:length(myfiles)
images{k}=imread(myfiles(k).name);
images{k} = imresize(images{k},[224 224]);
%to extract the whole breast
BW1 = imbinarize(images{k});
nhood = true(9);
closeBW1 = imclose(BW1,nhood);
roughMask = imfill(closeBW1,'holes');
BW2 = bwareafilt(roughMask,1);
I2=images{k};
I2(~BW2)=0;
images{k}=I2;
temp=images{k};
%normalize the image
images{k}=temp-min(temp(:))/max(temp(:))-min(temp(:));
images{k}=adapthisteq(images{k});
baseFileName = sprintf('Image #%d.png', k);
fullFileName = fullfile(newfolder, baseFileName);
imwrite(images{k}, fullFileName);
%%%%%
end
Image Analyst
on 10 Sep 2018
Image Analyst
on 10 Sep 2018
That algorithm looks really, really bad and amateurish. Which paper published that one? I find it hard to believe that would work.
Afaf Saad
on 10 Sep 2018
this is not the whole system, i didn't finish yet. i followed the attached paper, i did the pre-processing that he mentioned. have a look if there is any comments. and tell me.
Afaf Saad
on 10 Sep 2018
it already works, just extracting the whole breast and getting rid of the tags. he didn't mention extra process to do.
Answers (1)
Image Analyst
on 10 Sep 2018
See attached demo.
11 Comments
Image Analyst
on 10 Sep 2018
Yes, but I have other stuff to do. This image has different brightness, so why don't you scan the outer edge of the image to find out what a good threshold would be?
Image Analyst
on 11 Sep 2018
You can extract the top 3 rows like this
topRows = grayImage(1:3, :);
leftColumns = grayImage(:, 1:3);
rightColumns = grayImage(:, end-2:end);
By looking at those, and assuming that the gray levels will either represent pectoral muscle, or black background, you will be able to determine a good guess for the threshold.
AHT.fatima
on 12 May 2022
Edited: AHT.fatima
on 12 May 2022
hello to all thank you for your efforts but it only works with this image but not the others. there is a part of the region of interest which is removed when applying the code with another image...please my friends or i add exactly the three lines in this code to remove the pectoral muscle and not a part of ROI and have the best results please...
Image Analyst
on 12 May 2022
Edited: Image Analyst
on 12 May 2022
@AHT.fatima you forgot to attach the "other image" that it doesn't work for. How can I fix it otherwise? Do we know for a fact that the pectoral muscle will always in in one of the corners?
You say "please my friends or i add exactly the three lines in this code to remove the pectoral muscle" so if I don't write any more code for you, then what are those three lines of code you'll add that will do it?
AHT.fatima
on 12 May 2022
Thank you for your answer, I am working with this code you shared.. I try it with several photos but it does not give the required results because I want to remove the pectoral muscle to finally only get our ROI without any loss or deletion at its level.
Image Analyst
on 12 May 2022
@AHT.fatima I don't think that is robust. See my new code below, which is more robust. It deletes any bright blob in the upper right or upper left corner.
The problem is you're dealing with a screenshot rather than the original image. I've made a few changes to just crop the image to what you'd have if you had the original image.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clearvars; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
folder = pwd;
baseFileName = 'mammo B5.png';
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~exist(fullFileName, 'file')
% The file doesn't exist -- didn't find it there in that folder.
% Check the entire search path (other folders) for the file by stripping off the folder.
fullFileNameOnSearchPath = baseFileName; % No path this time.
if ~exist(fullFileNameOnSearchPath, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist in the search path folders.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
rgbImage = imread(fullFileName);
% Display the image.
subplot(2, 3, 1);
imshow(rgbImage, []);
title('Original RGB Screenshot Image', 'FontSize', fontSize, 'Interpreter', 'None');
hp = impixelinfo;
axis('on', 'image'); % Make sure image is not artificially stretched because of screen's aspect ratio.
% Get the dimensions of the image.
% numberOfColorChannels should be = 1 for a gray scale image, and 3 for an RGB color image.
grayImage = rgbImage; % Initialize.
[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(:, :, 1); % Take red channel.
end
% The image is not the original image - it's a screenshot that has a white frame around it.
% Get rid of white frame and crop image.
grayImage = grayImage(55:1078, 183:951);
% Update image size.
[rows, columns, numberOfColorChannels] = size(grayImage);
% Display the image.
subplot(2, 3, 2);
imshow(grayImage, []);
hp = impixelinfo;
title('Cropped Gray Scale Image', 'FontSize', fontSize, 'Interpreter', 'None');
axis('on', 'image'); % Make sure image is not artificially stretched because of screen's aspect ratio.
%------------------------------------------------------------------------------
% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0.04, 1, 0.96]);
drawnow;
% Display the histogram.
subplot(2, 3, 3);
imhist(grayImage);
grid on;
title('Histogram of Gray Scale Image', 'FontSize', fontSize, 'Interpreter', 'None');
% Turn into a binary image to get the pectoral muscle.
lowThreshold = 130;
highThreshold = 255;
% https://www.mathworks.com/matlabcentral/fileexchange/29372-thresholding-an-image?s_tid=srchtitle
% [lowThreshold, highThreshold] = threshold(lowThreshold, highThreshold, grayImage)
binaryImage = grayImage > lowThreshold & grayImage <= highThreshold;
% Display the binary image.
subplot(2, 3, 4);
imshow(binaryImage, []);
caption = sprintf('Bright Regions Mask Image');
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
hp = impixelinfo;
axis('on', 'image'); % Make sure image is not artificially stretched because of screen's aspect ratio.
drawnow;
% Extract only blob in the upper left or upper right corners.
pectMask = bwselect(binaryImage, 1, 1) | bwselect(binaryImage, columns, 1);
% Fill holes
binaryImage = imfill(pectMask, 'holes');
% Display the binary image.
subplot(2, 3, 5);
imshow(pectMask, []);
caption = sprintf('Pectoral Mask Image');
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
hp = impixelinfo;
axis('on', 'image'); % Make sure image is not artificially stretched because of screen's aspect ratio.
drawnow;
% Erase the gray scale image there.
grayImage(pectMask) = 0;
% Display the masked image.
subplot(2, 3, 6);
imshow(grayImage);
axis('on', 'image'); % Make sure image is not artificially stretched because of screen's aspect ratio.
caption = sprintf('Image with Pectoral Muscle Masked out.');
title(caption, 'FontSize', fontSize);
drawnow;
AHT.fatima
on 15 May 2022
hello everyone, can someone explain this code to me please .... it gives me good results but I did not understand its principle (by the way it is a code for the removal of the pectoral muscle after binarization)...
Image Analyst
on 15 May 2022
Edited: Image Analyst
on 15 May 2022
I did explain my code, in the comments. Nearly every small snippet of code is explained. Which comment don't you understand? I don't know who wrote that code that you attached. You'd have to ask them if you'd rather use their code than mine. I really don't have time to re-write their code correctly, like by adding in the code missing from the beginning to read in the images and assign variables, put in the missing comments, etc.
See Also
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 (한국어)