MATLAB: Contrast image processing ultrasound

drawrectangleImage Processing Toolboxroistudent

Hi guys we are calculating the contrast of a cyst inside an ultrasound image. With the code we select the square ROI manually, but then we also need a ROI of the same size to calculate the background. Then extract from the medium cyst the level of gray and variance. Can you help us?
im= imread('_258.tif');
imshow(im);
c_im=imcrop(im);
c_im=rgb2gray(c_im);
imshow(c_im);
xmed=mean2(c_im);
xstd=std2(c_im);

Best Answer

ALESSIA:
Try this little demo:
grayImage = imread('Cameraman.tif');
subplot(2, 2, 1);
imshow(grayImage);
g = gcf;
g.WindowState = 'maximized';
title('Gray Scale Image', 'FontSize', fontSize);
uiwait(helpdlg('Click and drag to draw the inner circular region.'));
roi = drawcircle('Color', 'red')
innerMask = roi.createMask;
innerXY = roi.Vertices;
uiwait(helpdlg('Click and drag to draw the outer circular region.'));
roi = drawcircle('Color', 'green')
outerMask = roi.createMask;
outerXY = roi.Vertices;
% Exclude the inner mask from the outer mask.
outerMask = xor(outerMask, innerMask);
% Get the mean in the circles.
innerMeanGL = mean(grayImage(innerMask))
outerMeanGL = mean(grayImage(outerMask))
subplot(2, 2, 2);
imshow(innerMask);
title('Inner Mask Image', 'FontSize', fontSize);
subplot(2, 2, 3);
imshow(outerMask);
title('Outer Mask Image', 'FontSize', fontSize);
subplot(2, 2, 4);
imshow(grayImage);
hold on;
% Draw the circles.
plot(innerXY(:, 1), innerXY(:, 2), 'r-', 'LineWidth', 2);
plot(outerXY(:, 1), outerXY(:, 2), 'g-', 'LineWidth', 2);
caption = sprintf('Inner mean GL = %.3f, Outer mean GL = %.3f', innerMeanGL, outerMeanGL);
title(caption, 'FontSize', fontSize);
If this answers your question, could you "Accept this answer"? Thanks in advance.