Maybe a simpler way to think about this is if i know the spacing of a meshgrid (dx=dy) and a certain point (xx,yy) near the centre it passes thru, how to create this and cover as much of the image as possible.
Projecting a meshgrid from a sub-image (ROI) back to main image and expanding the meshgrid.
10 ビュー (過去 30 日間)
古いコメントを表示
Hi, I have an image of a sample with a regular grid on, except the image has distortion so the actual image doesn't display a regular grid. My aim is the splat a real grid over the image to then work out the distortion in the image.
I define what the real grid is by using the part of the central yellow bit of the image as below, and use features near the edge as shown in the red boxes to define my grid spacing.
Once I have my grid spacing and my starting location, I create the grid on this ROI.
The white crosses indicate my real grid spacing (with the spacing fixed in both x & y).
As i know how the grid spacing and its starting point in this image, I know want to be able to put this grid back onto the larger image and expand the grid (outwards) so it fills the whole image.
I used meshgrid to create this:
[X,Y] = meshgrid(realx,realy);
plot(ax2,X,Y,'w+','MarkerSize',30); drawnow
The only link between the ROI and the main image is that the centre of the ROI coincides with the centre of the main image (you can just see the cyan cross in the ROI image representing the centre of this image.
This is how I got my ROI: (showing the link between it and the main image)
Image=getimage(ax1); % ax1 is the uiaxes of the main image
[sy,sx]=size(Image);
hold(ax1,'on');
hx=round(sx/2); hy=round(sy/2);
plot(ax1,hx,hy,'c+');
ROI = getROI(app,Image, ax2); % ax2 is the uiaxes of the smaller ROI image
and getROI is defined as
function ROI = getROI(app,Image, ax)
%parentAxis is axis to display the ROI on
[sy,sx]=size(Image);
delta=str2double(app.ROIHalfWidthDropDown.Value); %This is typically 500
x=round(sx/2); y=round(sy/2);
ROI = Image(round(y)-delta:round(y)+delta, round(x)-delta:round(x)+delta);
%Add ROI to UIAXES
cla(ax,'reset');
imagesc(ax, ROI);
colormap(ax,'gray'); axis(ax,'image'); set(ax,'xtick',[]); set(ax,'ytick',[]);
%-----
end
So my questions are:
1: How to put the meshgrid back into the main image
2: How to expand it so it fills the image (or at least most of it)
Thanks for any help
Jason
回答 (1 件)
Yatharth
2024 年 5 月 22 日
Hi Jason,
To overlay this grid on the main image, you need to ensure that the grid is correctly scaled and aligned with the main image. Since you've mentioned that the center of the ROI coincides with the center of the main image, this simplifies the alignment process.
You need to calculate the scale factor based on the ratio of the main image's dimensions to the ROI's dimensions. However, since your grid spacing is fixed, you'll be expanding the number of grid points instead of physically scaling the grid lines.
Attaching a code snippet to guide you through scaling and overlaying the grid. It assumes realx and realy have been defined based on your ROI analysis.
% Assuming realx and realy are the grid spacings determined from the ROI
% Calculate the number of grid points needed to cover the main image
[sy, sx] = size(Image); % Size of the main image
numPointsX = ceil(sx / realx); % Number of points in X-direction
numPointsY = ceil(sy / realy); % Number of points in Y-direction
% Generate a new meshgrid that covers the entire main image
[X, Y] = meshgrid(linspace(1, sx, numPointsX), linspace(1, sy, numPointsY));
% Plotting the grid on the main image
hold(ax1, 'on'); % Ensure the main image axis is set to hold on
plot(ax1, X, Y, 'w+', 'MarkerSize', 10); % Adjust MarkerSize as needed
hold(ax1, 'off');
I hope this answers your query.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で 3-D Volumetric Image Processing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!