How to save pixel values from set of images and store them in ASCII format?

11 次查看(过去 30 天)
I have set of TIFF images, each corresponding to particular wavelength. For example, first image corresponds to 225.197nm, while the next one corresponds to 225.198nm. This way I have images that corresponds to about 100 different wavelengths. For a particular pixel in each of those images, I would like to extract the pixel values and put them like the attached file in two different columns. Any help will be greatly appreciated.
  2 个评论



Image Analyst
Image Analyst 2018-1-24
编辑:Image Analyst 2018-1-24
Use the FAQ to create a 3-D image, if there are not too many of them. Let's say you have 50 images, each with a different wavelength, then you'd do
image3d = zeros(rows, columns, numImages);
for k = 1 : numImages
thisImage = imread(...........
image3d(:,:,k) = thisImage;
Then scan the image, writing out each spectrum. You should have an array that says what the wavelength is for each image.
[rows, columns, numImages] = size(image3d);
count = 1;
for row = 1 : rows
for col = 1 : columns
thisSpectrum = image3d(row, col, :);
filename = sprintf('Spectrum %d.txt', count);
fileID = fopen(filename, 'wt');
fprintf(fileID, '%f, %f\n', wavelengths, thisSpectrum);
  10 个评论
Syed Mashruk
Syed Mashruk 2018-1-26
solved it with the following code:
fprintf(fileID, '%f %f\n', [wavenumbers(:), thisSpectrum(:)].');
Many thanks for your help.


更多回答(1 个)

Walter Roberson
Walter Roberson 2018-1-24
Read the files in and store into a 3D array, with the third dimension increasing with wavelength. Once you have everything read in, loop over the pixels, fopen() an appropriate file name, fprintf() the wavelengths and a 3D column extracted from the array.
  2 个评论
Walter Roberson
Walter Roberson 2018-1-24
Do not fopen() the tif files yourself. Use imread(), or use the Tiff class (and make sure you clear the tiff object when you are done with it.)



Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by