How to save pixel values from set of images and store them in ASCII format?
2 views (last 30 days)
Show older comments
Syed Mashruk
on 24 Jan 2018
Commented: Syed Mashruk
on 26 Jan 2018
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 Comments
Walter Roberson
on 24 Jan 2018
Do I understand correctly that if your image was (for example) 512 pixels by 768 pixels, that you would want (512*768) = 393216 different files created, one for each pixel position, each file containing the information for all of the wavelengths at that position ?
Accepted Answer
Image Analyst
on 24 Jan 2018
Edited: Image Analyst
on 24 Jan 2018
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;
end
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);
fclose(fileID);
end
end
10 Comments
More Answers (1)
Walter Roberson
on 24 Jan 2018
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 Comments
Walter Roberson
on 24 Jan 2018
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.)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!