How can I control the voxel size using 'imwrite'?
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello All,
I have an input tiff file image that has 342 slices, and I would like to extract each slice individually and save as a separate file.
% x = imread("inputTiffFile.tif", 100);
% imwrite(x, "slice_100.tif");
% x = imread("inputTiffFile.tif", 163);
% imwrite(x, "slice_163.tif");
However, I have one problem: The voxel spacing in the input image is [1, 1, 1], but the voxel spacing after using 'imwrite' is changed to [0.352778, 0.352778, 1]. I require the voxel spacing to be same as input.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/796679/image.png)
Any inputs on how to avoid this change in voxel size would be very helpful.
Thanks,
0 Kommentare
Antworten (1)
Shreshth
am 16 Jan. 2025 um 9:02
Hi Harsha,
To avoid the change in voxel size when using the "imwrite" function in MATLAB, you can specify the resolution of the output image using the 'Resolution' name-value pair argument. Here's an example:
imwrite(x, "slice_100.tif", 'Resolution', [1, 1, 1]);
% Note - [1, 1, 1] specifies that the voxel spacing should be the same as the input image.
Please refer to the following MathWorks documentation for more information on the “imwrite” function and 'Resolution' name-value pair argument:
Hope this helps!
1 Kommentar
Walter Roberson
am 16 Jan. 2025 um 20:30
Note that the Resolution option of imwrite() is valid only for TIFF output files.
If you happen to want to output as PNG, then you would use XResolution and YResolution and ResolutionUnit
imwrite() does not support writing resolution for any file types other than TIFF or PNG. If you happen to want to write JPEG files then you need to resort to using external functions to write EXIF information to the image, as imwrite() does not support writing EXIF (writing EXIF would be a very useful enhancement to imwrite())
Siehe auch
Kategorien
Mehr zu GigE Vision Hardware finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!