How can I create a surface plot from ROIs (9) in an image?
1 次查看(过去 30 天)
显示 更早的评论
I need to input an image, create 9 equal ROIs, and output a surface plot of pixel x pixel to show the 9 ROIs
4 个评论
DGM
2024-6-28
To be clear, you want to display the image content selected by each mask region, right?
Does it make more sense to display all the subimages together in a single surf?
% input
inpict = imread('cameraman.tif');
% parameters
roisize = [100 100]; % [y x]
roioffset = [10 10; 128 128]; % [y x]
% generate a mask somehow
nblobs = size(roioffset,1);
mask = false(size(inpict));
for k = 1:nblobs
rows = roioffset(k,1):roioffset(k,1) + roisize(1) - 1;
cols = roioffset(k,2):roioffset(k,2) + roisize(2) - 1;
mask(rows,cols) = true;
end
% apply the mask
Z = inpict;
Z(~mask) = 0; % for float and unsigned-integer images
% show it as an image so we know what we're looking at
figure(1)
imshow(Z)
% display it as a surf
figure(2)
surf(Z)
shading flat
Or would it be easier to read if the subimages are displayed individually?
% input
inpict = imread('cameraman.tif');
% parameters
roisize = [100 100]; % [y x]
roioffset = [10 10; 128 128]; % [y x]
% directly get image content in each blob
% instead of bothering with a mask
nblobs = size(roioffset,1);
subimages = cell(nblobs,1);
for k = 1:nblobs
rows = roioffset(k,1):roioffset(k,1) + roisize(1) - 1;
cols = roioffset(k,2):roioffset(k,2) + roisize(2) - 1;
subimages{k} = inpict(rows,cols);
end
% display each subimage as a surf
for k = 1:nblobs
% you might want to do a more thoughtful figure setup
figure
% the surf
surf(subimages{k})
shading flat
end
回答(1 个)
Umar
2024-6-28
Hi Gabriel,
To add 9 ROIs with specific positions in Matlab, you can define the positions of the rectangles using the rectangle function.
For more information on rectangle function, please refer to
https://www.mathworks.com/help/matlab/ref/rectangle.html#
Here's a sample code snippet to create and outline the ROIs on your image:
% Define the positions of the 9 ROIs (x, y, width, height)
roiPositions = [x1, y1, 100, 100; x2, y2, 100, 100; ...]; % Define all 9 ROIs
% Display the image
imshow(yourImage);
hold on; % To overlay rectangles on the image
% Loop through each ROI position and draw the rectangle
for i = 1:size(roiPositions, 1) rectangle('Position', roiPositions(i, :), 'EdgeColor', 'r', 'LineWidth', 2); end
hold off; % Release the hold
% Create a surface plot for each ROI
for i = 1:size(roiPositions, 1) roi = yourImage(roiPositions(i, 2):roiPositions(i, 2)+99, roiPositions(i, 1):roiPositions(i, 1)+99); figure; surf(roi); title(['Surface Plot for ROI ', num2str(i)]); end
The above snippet code will help you add 9 ROIs as rectangles at specific positions in your image and generate surface plots for each ROI to visualize the varying intensities.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!