How to obtain information from a ROI from an image generated with imagesc

29 views (last 30 days)
I have images of ultrasound scans that are generated using imagesc, they will typically look like:
The higher intensity zones in the radial pattern represent ultrasonic reflectors, i.e., defects in a test sample.
The data has been normalised to the max value within the defect zone, so the max pixel value of any defect is 0 dB.
Not all defects have a 0 dB max value and I would like to find a simple way to use a ROI to determine the max pixel value within that ROI.
For example, I can use "drawrectangle" to create the ROI.
How can I then find out the max pixel value from such ROI without having to zoom in and manually determine the max value?

Accepted Answer

Matt J
Matt J on 15 Nov 2023
Edited: Matt J on 15 Nov 2023
Use the ROI's createMask() method:
max(yourImage(roi.createMask))
  3 Comments
Matt J
Matt J on 15 Nov 2023
Edited: Matt J on 15 Nov 2023
The line of code I showed you should work as written as long as you have created a handle to the roi in your workspace as well, e.g.,
roi=drawrectangle(___)

Sign in to comment.

More Answers (2)

Yousef
Yousef on 15 Nov 2023
Moved: Matt J on 15 Nov 2023
To find the maximum pixel value within a Region of Interest (ROI) in MATLAB after using `drawrectangle` to define the ROI on your ultrasound scan image, you can follow these steps:
1. Use `drawrectangle` to create the ROI and position it where you want on the image.
2. Once you have defined the ROI, you can obtain the position and size of the rectangle.
3. Extract the pixel values within this rectangle from the image data.
4. Find the maximum pixel value within this extracted subset.
Here is an example MATLAB code snippet that demonstrates this process:
MATLAB code:
% Assume 'img' is your ultrasound image data
% Display the image
figure;
imagesc(img);
colormap('jet'); % Assuming you are using a colormap similar to the images you've uploaded
colorbar;
% Use drawrectangle to let the user define the ROI
h = drawrectangle;
% Wait for the ROI to be finalized
customWait(h);
pos = round(h.Position);
% Extract coordinates and dimensions of the rectangle
x_begin = pos(1);
y_begin = pos(2);
x_width = pos(3);
y_height = pos(4);
% Extract the pixel values within the ROI
roi_data = img(y_begin:(y_begin+y_height), x_begin:(x_begin+x_width));
% Find the maximum pixel value within the ROI
max_value = max(roi_data(:));
% Output the maximum pixel value
disp(max_value);
% Custom wait function to pause the script until the rectangle is double-clicked
function customWait(hROI)
% Listen for 'ROICreated' event
addlistener(hROI, 'ROICreated', @(src, evt) setappdata(gcbf, 'waitDone', true));
% Wait until the ROI creation is done
waitfor(gcbf, 'waitDone');
end
```
This code will display the maximum pixel value within the selected ROI in the MATLAB Command Window. You can modify the `customWait` function based on how you want the user to finalize the ROI, such as double-clicking or pressing the Enter key. Note that this code assumes that the pixel values of your image are accessible in the variable `img` and that the image has already been normalized as you described.

Image Analyst
Image Analyst on 15 Nov 2023

Categories

Find more on Convert Image Type in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!