How to remove the pectoral muscle from the mammogram?

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

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?
I posted different images to take a look
Did you see the images?
Yes, but which one of these papers are you trying to implement: Pectoral Muscle Removal?
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.
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
That algorithm looks really, really bad and amateurish. Which paper published that one? I find it hard to believe that would work.
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.
it already works, just extracting the whole breast and getting rid of the tags. he didn't mention extra process to do.
what is your opinion ?

Sign in to comment.

Answers (1)

See attached demo.

14 Comments

thank you for you effort, but it works only with this image but the others not. there is a part of interest region is removed when applying the code with another images. :( :(
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?
Ok,,How to scan the image? you mean to scan the matrix by vision?
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.
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...
@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?
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.
@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;
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)...
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.
Thanks for this code. Please how can one cite your work for research purpose?
@Muhammad just say you got it from Image Analyst on the Mathworks Central Answers community forum and give the URL
which you can also get by clicking on the chain links icon at the top of my post next to my name. Good luck on your research. 🙂

Sign in to comment.

Categories

Find more on Image Processing and Computer Vision in Help Center and File Exchange

Asked:

on 10 Sep 2018

Commented:

on 10 Jun 2025

Community Treasure Hunt

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

Start Hunting!