How to obtain information from a ROI from an image generated with imagesc
39 views (last 30 days)
Show older comments
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?
0 Comments
Accepted Answer
Matt J
on 15 Nov 2023
Edited: Matt J
on 15 Nov 2023
max(yourImage(roi.createMask))
More Answers (2)
Yousef
on 15 Nov 2023
Moved: Matt J
on 15 Nov 2023
HI @Alan Keenan
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
on 15 Nov 2023
- circle_masking_demo.m
- circle_masking_demo_drawcircle.m
- draw_multiple_polygons.m
- drawCircle_demo.m
- drawline_demo.m
- drawpoint_demo.m
- drawpolygon_demo.m
- drawrectangle_demo.m
- freehand_drawing_demo.m
- freehand_masking_demo.m
- mask_and_crop_image_by_ellipse.m
- mask_multiple_ellipses.m
- roifill_color.m
- roifill_demo.m
See various roi and masking demos I have attached.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!