contrast image processing ultrasound
Show older comments
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 Comments
Image Analyst
on 16 May 2020
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
on 16 May 2020
Accepted Answer
More Answers (1)
Image Analyst
on 16 May 2020
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))

Categories
Find more on ROI-Based Processing in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
