How to resize an MRI image data keeping the original field of view?
조회 수: 22 (최근 30일)
이전 댓글 표시
I have few MRI datasets, where the dimension of the dataset is 320x640x16. First two dimensions are row and column and the last one is Coil dimension. I want to resize the row and column into 256x256x16, keeping the original Field of view. I tried the below code. But it make changes into the field of view and it cut the slices.
new_data = zeros([256,256,16]);
load brain.mat;
new_data(:,:,:) = raw_data(33:288, 193:448, :);
댓글 수: 0
채택된 답변
Image Analyst
2022년 8월 4일
[rows, columns, numberOfSlices] = size(raw_data)
new_data = zeros(256, 256, numberOfSlices, class(raw_data));
for k = 1 : numberOfSlices
thisImage = raw_data(:, :, k);
new_data(:, :, k) = imresize(thisImage, [256, 256]);
end
댓글 수: 5
Image Analyst
2022년 8월 4일
편집: Image Analyst
2022년 8월 4일
Not sure where you got that weird looking image but this works fine
s = load('brain.mat');
raw_data = s.raw;
[rows, columns, numberOfSlices] = size(raw_data)
new_data = zeros(256, 256, numberOfSlices, class(raw_data));
for k = 1 : numberOfSlices
thisImage = raw_data(:, :, k);
subplot(2, 1, 1);
imshow(thisImage, [])
axis('on', 'image');
new_data(:, :, k) = imresize(thisImage, [256, 256]);
subplot(2, 1, 2);
imshow(new_data(:, :, k), [])
axis('on', 'image');
end
The original and resized images are shown below:
However you only put one 2-D image into the .mat file, not a 3-D image.
추가 답변 (1개)
Matthew Pepich
2022년 8월 4일
I was too slow with my answer and @Image Analyst did it better, but here is another option that just samples the image. This works for displaying a thumbnail where interpolation is not important, but "imresize" is preferred if you need accuracy.
% Get your original image
C = imread('landOcean.jpg');
% Produce a scaled down image
scale = 0.10;
x = round( linspace( 1, size(C,1), size(C,1)*scale ) );
y = round( linspace( 1, size(C,2), size(C,2)*scale ) );
C2 = C(x, y, :);
% Display results
figure();
subplot(2,1,1);
image(C);
axis image;
title( sprintf('Size = %d x %d',size(C,[1 2])) )
subplot(2,1,2);
image(C2);
axis image;
title( sprintf('Size = %d x %d (Scaled to %g%%)',size(C2,[1 2]), 100*scale) )
댓글 수: 2
Matthew Pepich
2022년 8월 4일
Would it still work to use "linspace" to generate even indices? Ignoring the display part of my solution, try just using this to produce your indices:
x = round( linspace( 1, size(raw_data,1), 256 ) );
y = round( linspace( 1, size(raw_data,2), 256 ) );
new_data = raw_data(x, y, :);
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!