- Imagesc – Display image with scaled colours (Mathworks documentation): https://in.mathworks.com/help/matlab/ref/imagesc.html?searchHighlight=imagesc&s_tid=srchtitle_support_results_1_imagesc
- Scatter plot (Mathworks documentation): https://in.mathworks.com/help/matlab/ref/scatter.html?searchHighlight=Scatter%20plot&s_tid=srchtitle_support_results_1_Scatter%20plot
- Non-uniform contour/imagesc/colorbar (File Exchange): https://in.mathworks.com/matlabcentral/fileexchange/65424-non-uniform-contourf-imagesc-colorbar
- Imagesc2(varargin) for enhanced control (File Exchange): https://in.mathworks.com/matlabcentral/fileexchange/52484-imagesc2-varargin
How can I plot intensity values given pixel positions?
12 ビュー (過去 30 日間)
古いコメントを表示
Hi!
I have a matrix with intensity values that are the pixels of an image 318x1000. I have to locate these pixels in fixed positions.
For example, if the first row is
I=[96 99 96 100 99 98]
x1=[3.38 3.41 3.45 3.49 3.535 3.5738]
y1=[1 1 1 1 1 1]
the second one
x2=[4.35 4.46 4.47 4.49 4.60 4.66]
y2=[2 2 2 2 2 2]
how can I plot them in the same image? imagesc just define the I(1,1) and I(318,1000) pixel position.
0 件のコメント
回答 (1 件)
Sanchari
2024 年 5 月 2 日
Hello Valeria,
To plot intensity values located at specific positions as described, especially when the positions do not align with a regular grid, you can't directly use “imagesc” because “imagesc” assumes a regular, evenly spaced grid for plotting. Instead, you should consider using a scatter plot or creating a custom grid that maps your specific (x, y) positions to the intensity values and then interpolating between these points to create an image that can be displayed with “imagesc” or similar functions.
Given your requirement and the example data, here are some ways to plot the intensity values at their specified (x, y) positions using either a scatter plot approach or interpolation approach.
1. Scatter Plot Approach:
This approach directly plots each point with its intensity value represented by colour. This method is suitable if you’re okay with a non-continuous representation of your data.
% Example data
I = [96 99 96 100 99 98; ... % Intensities for first row
95 97 93 94 96 92]; % Intensities for second row (example)
x1 = [3.38 3.41 3.45 3.49 3.535 3.5738];
y1 = [1 1 1 1 1 1];
x2 = [4.35 4.46 4.47 4.49 4.60 4.66];
y2 = [2 2 2 2 2 2];
% Combine your x, y, and I data
x = [x1, x2]; % Assuming x1 and x2 are row vectors
y = [y1, y2]; % Same for y1 and y2
I_combined = [I(1,:), I(2,:)]; % Flatten I to a single row
% Create a scatter plot
scatter(x, y, 40, I_combined, 'filled'); % Adjust the size (40) as needed
colorbar; % Show color scale
axis ij; % Adjust the axis orientation if needed
xlabel('X Position');
ylabel('Y Position');
title('Intensity Values at Specific Positions');
Output:
2. Interpolation Approach:
If you prefer a continuous representation, you can interpolate the intensity values onto a regular grid and then use imagesc or similar functions. This approach is more complex and involves selecting an interpolation method that suits your data.
% Define a regular grid that covers your x and y range
[xq, yq] = meshgrid(min(x):0.01:max(x), min(y):0.01:max(y)); % Adjust grid resolution as needed
% Interpolate the intensity values onto this grid
Iq = griddata(x, y, I_combined, xq, yq, 'linear'); % Choose an appropriate interpolation method ('linear', 'cubic', etc.)
% Plot the interpolated intensity values
imagesc([min(x) max(x)], [min(y) max(y)], Iq);
axis xy; % Correct the axis orientation
colorbar; % Show color scale
xlabel('X Position');
ylabel('Y Position');
title('Interpolated Intensity Image');
Output:
Both approaches serve different purposes: the scatter plot method shows discrete data points with their exact intensity values, while the interpolation approach creates a continuous image that approximates intensity values between the specified positions.
Please refer to the following links to know further about related queries:
Hope this helps!
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Blue についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!