2D matrix resize or interpolation
28 次查看(过去 30 天)
显示 更早的评论
Hello,
I'm new to matlab and I'm not sure what would be the best way to do the following.
I have an image/data matrix, I, of size (rows,cols) = (y,x) = [384,512].
The spatial resolution in the x direction is 0.078021 cm (total span is ~40cm)
The spatial resolution in the y direction is 0.078021 (total span is ~30cm)
Q1.
If I would like to have a finer sampling of the data by doubling the samples (eg Inew = [768, 1024], which function would you suggest?
Q2.
If I had another separate image but with offset x,y values, how would I interpolate this data onto the same grid as the other matrix?
Thank you for your help,
RR
ps. I found some info on the interp2 function? not sure if this is the best function to use?
ps. I have attached a zip file with
- dicom image (of a radiotherapy dose on a single plane - my image)
- excel workbook with the data extracted
- an m script with what I tried to do but I got an error
Error using griddedInterpolant
The grid must be created from grid vectors which are strictly monotonically increasing.
Error in interp2>makegriddedinterp (line 228)
F = griddedInterpolant(varargin{:});
Error in interp2 (line 136)
F = makegriddedinterp(X, Y, V, method,extrap);
Error in LoadDosePlaneBailey2D (line 70)
Id_cgy_q = interp2(X,Y,Id_cgy,Xq,Yq);
0 个评论
回答(3 个)
Cris LaPierre
2025-1-10
编辑:Cris LaPierre
2025-1-10
Q2: What type of images are you working with? Please share an example. You can attach images to your post using the paperclip icon.
16 个评论
Cris LaPierre
2025-1-26
编辑:Cris LaPierre
2025-1-27
I'm defnitely not an expert in this space, so I'm still confused. Based on the metadata in the dsf files
- Image_measured_30x40.dxf is actually 21.5x28.7
- Image_prediction1_43x43.dxf is actually 31.1x31.1
- Image_prediction2_30x40.dxf is actually 21.4x28.5
It looks like you have a 2-step process - first to extract the desired region using indexing, then resizing. Given that, I think the best approachis to use imresize on the extracted iage. Pick the approprite method for your task.
Cris LaPierre
2025-1-27
Heres a function that will read in your dxf files. Not necessarily the best code, but does the job.
unzip Image_prediction1_43x43.zip
params = readDXF('Image_prediction1_43x43.dxf');
figure
imagesc(params.Pixels)
Xsz = params.Size1*params.Res1
Ysz = params.Size2*params.Res2
function data = readDXF(fname)
data = struct;
fid = fopen(fname);
while ~feof(fid)
ln = fgetl(fid);
[param,val] = strtok(ln,"=");
switch param
case {'[General]','[Geometry]','[Interpretation]','[Patient]','[Field]','[PortalDose]'}
continue
case '[Data]'
fseek(fid,0,'eof');
fgetl(fid);
otherwise
val = strtok(val,'=');
pat = asManyOfPattern(characterListPattern("0123456789-+."));
nums = extract(val,pat);
if length(val)==length(nums{1})
data.(param) = str2double(val);
else
data.(param) = val;
end
end
end
fclose(fid);
val = readmatrix(fname,'FileType','text','NumHeaderLines',48);
data.Pixels = val;
end
Walter Roberson
2025-1-10
If I would like to have a finer sampling of the data by doubling the samples (eg Inew = [768, 1024], which function would you suggest?
If you were willing to have Inew = [767, 1023] instead of [768, 1024] then you can average adjacent rows and adjacent columns and manually insert the averaged values into the proper place. To be honest, though, calling interp2() is a heck of a lot easier.
The reason the output would be Inew = [767, 1023] instead of [768, 1024] is that you would be calculating new points between each existing point. If you had 3 points across then you have 2 intermediate points, for a total of 5. Calculating intermediate points gets you output of size 2*N-1 not output of size 2*N
Getting output exactly twice the original size requires interpolation at "just less than half" apart, like positions 1, 1.49, 1.98, 2.47,...
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!