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
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
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 个评论
Syed Mashruk
Syed Mashruk 2018-1-26
编辑:Syed Mashruk 2018-1-26
I am still not getting my text file in the desired following form:
44406 216
44406.2 216
44406.4 215
44406.6 215
44406.8 214
Instead getting in the following form:
44406 44406.2
44406.4 44406.6
44406.8 216
216 215
215 214
I tried following code:
fprintf(fileID, '%f %f\n', wavenumbers(count), thisSpectrum);
And I am getting following message:
Error using vertcat
Dimensions of matrices being concatenated are not consistent.
Any suggestions?
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 个评论
Syed Mashruk
Syed Mashruk 2018-1-24
Thanks Walter but when I am trying to use fopen() like the following code:
[listOfFiles, folder] = uigetfile ('*.tif', 'Select your image', 'MultiSelect', 'on');
for j=1:length(listOfFiles)
fullFileName = fullfile(folder, listOfFiles{j});
fileID=fopen(fullFileName);
end
I selected 500 tiff files and I am getting the following message:
Too many open files. Close files to prevent MATLAB instability.
Caused by: Message Catalog MATLAB:services was not loaded from the file. Please check file location, format or contents
Is there any way around it?
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.)

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Timing and presenting 2D and 3D stimuli 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by