- Read the input image using "imread". Resize the image for full resolution display using "imresize".
- Set the width and height for each "ROI". Specify the number of ROIs to be drawn in both "X" and "Y" directions.
- Initialize arrays to hold the positions of ROIs in both "X" and "Y" directions.
- Display the original image using "imshow". Use "hold on" to allow drawing multiple ROIs on the same image. Loop through each calculated position and draw rectangles to represent ROIs using the "rectangle" function.
- For each ROI, extract the corresponding region from the image. Calculate the average intensity within this region using the "mean" function. Use the "text: function to display the calculated average intensity values at the center of each ROI on the image. Use "hold off" to finalize the drawing on the image. Display the image with ROIs and their corresponding intensity values.
Obtain intensity values within the ROIs drawn on image in this script. Then, write and display intensity values within the ROIs on the image.
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
clear all
close all
% UUT image input
I = imread('UUT33.bmp');
R = imresize(I, [800 1000]); % Resize image to full res
% Define ROI size
ROIWidth = 100;
ROIHeight = 100;
% Number of ROIs in X and Y directions
numROIsX = 3;
numROIsY = 3;
% Calculate the step size for placing ROIs
stepX = floor(size(R, 2) / (numROIsX + 1));
stepY = floor(size(R, 1) / (numROIsY + 1));
% Initialize ROI positions
ROIPositionsX = zeros(numROIsX, 1);
ROIPositionsY = zeros(numROIsY, 1);
% Calculate ROI positions based on the step size
for i = 1:numROIsX
ROIPositionsX(i) = i * stepX - floor(ROIWidth / 2);
end
for j = 1:numROIsY
ROIPositionsY(j) = j * stepY - floor(ROIHeight / 2);
end
% Create ROIs and visualize
figure;
imshow(R); % Display the original image
hold on; % Hold the current plot
% Loop through each ROI position and draw rectangles on image
for i = 1:numROIsX
for j = 1:numROIsY
x = ROIPositionsX(i);
y = ROIPositionsY(j);
rectangle('Position', [x, y, ROIWidth, ROIHeight], 'EdgeColor', 'r', 'LineWidth', 2);
end
end
hold off; % Release hold on current plot
title('ROIs on image in exact positions');
This scirpt inputs an image and draws rectangle ROIs in specific positions on the image. I need to obtain the intensity values within all of the ROIs, and then write in /display the intensity values wihin all of the drawn ROIs on the image. Any ideas?
0 Kommentare
Antworten (1)
Maneet Kaur Bagga
am 11 Jul. 2024
Hi Gabriel,
I understand that you want to obtain the intensity values within the ROIs and display them on the image. Please refer to the following steps to achieve the same.
Please refer to the following code snippet for better understanding:
%extract the image data within each ROI
ROI = R(y:y+ROIHeight-1, x:x+ROIWidth-1, :);
%calculate average intensity of each ROI
avgIntensity = mean(ROI(:));
I hope this helps!
0 Kommentare
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!