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);

댓글 수: 2

Image Analyst
Image Analyst 2020년 5월 16일
Does the background box surround the cyst box, or is it beside it? Do you just want to manually drag out a box around the cyst, and then point to the center of the other background box?
ALESSIA PAPPA
ALESSIA PAPPA 2020년 5월 16일
the background sourrounds the cyst, but I need to calculate the average of gray level of the background selecting the ROI with the same dimension of cyst itself.

댓글을 달려면 로그인하십시오.

 채택된 답변

Image Analyst
Image Analyst 2020년 5월 17일
편집: Image Analyst 2020년 5월 17일

0 개 추천

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.

댓글 수: 2

ALESSIA PAPPA
ALESSIA PAPPA 2020년 5월 18일
Hi,I tried the code, but my image is made up of black cysts with respect to the background affected by "speckle" and the code does not detect any "inner mask image", therefore it does not calculate its average. How can I do?
We also tried to enter the standard deviation calculation but it does not do it.
Help please.
Image Analyst
Image Analyst 2020년 5월 18일
It doesn't matter what the image is, as long as it's gray scale. It doesn't care at all if what is inside the circles is light, dark, or in between. The code doesn't "detect" cysts - you specify where they are by drawing them. Then it looks at the gray levels inside the circles you drew. It does not matter at all what those gray levels are, it just gets their mean. It definitely does compute the mean. It's right there in the title bar. If it's not computing the mean for you, then it's because you removed the line where I call mean(). Same for standard deviation.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Image Analyst
Image Analyst 2020년 5월 16일

0 개 추천

Try this:
grayImage = imread('Cameraman.tif');
imshow(grayImage);
roi = drawrectangle
row1 = roi.Position(2);
row2 = roi.Position(2) + roi.Position(4);
col1 = roi.Position(1);
col2 = roi.Position(1) + roi.Position(3);
% Get the mean in that box
meanGL = mean2(grayImage(row1:row2, col1:col2))
% Compute area
height1 = (row2-row1 + 1)
width1 = (col2 - col1 + 1)
area = height1 * width1
% Make a box twice as big.
height2 = sqrt(2) * height1;
width2 = sqrt(2) * width1
% Get the midpoint
middleRow = mean([row1, row2])
middleCol = mean([col1, col2])
xline(middleCol, 'Color', 'r', 'LineWidth', 2);
yline(middleRow, 'Color', 'r', 'LineWidth', 2);
row1 = round(middleRow - height2/2)
row2 = round(middleRow + height2/2)
col1 = round(middleCol - width2/2)
col2 = round(middleCol + width2/2)
hold on
rectangle('Position', [col1, row1, width2, height2], 'EdgeColor', 'y', 'LineWidth', 2);
% Get the mean in that box
meanGL = mean2(grayImage(row1:row2, col1:col2))

질문:

2020년 5월 16일

댓글:

2020년 5월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by