How to save pixel values from set of images and store them in ASCII format?
6 次查看(过去 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 个评论
Walter Roberson
2018-1-24
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 ?
采纳的回答
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;
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 个评论
更多回答(1 个)
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
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!