Can't Open Image files?
5 views (last 30 days)
Show older comments
I was able to write and view photos as ".tiff" in grayscale just fine but now that I have altered the colormap to thermal I can no longer open them in file explorer any ideas?
g = gigecam;
executeCommand(g, 'AutoFocus');
img = snapshot(g);
I = imadjust(img,stretchlim(img),[]);
map = thermal;
imshow(I)
colormap(map);
folder = '/Users/Documents/ThermalPhotos/';
Filename = sprintf('image_%s.tiff',datestr(now,'mm-dd-yyyy_HH-MM-SS'));
fullFileName = fullfile(folder,Filename);
imwrite(I,map,fullFileName);
clear snapshot;
clear g
1 Comment
Image Analyst
on 18 May 2022
Save I to a .mat file. Then attach the .mat file and the .tiff file with the paperclip icon.
Answers (1)
prabhat kumar sharma
on 19 Feb 2024
Edited: prabhat kumar sharma
on 19 Feb 2024
Hi Jennifer,
It seems that after applying the thermal colormap, you're trying to save the image as a TIFF file. However, you need to ensure that the image is in the indexed format before saving it with a colormap. If I is not an indexed image, you need to convert it to one using rgb2ind.
Here's how you can modify your code to achieve this:
I = imadjust(img, stretchlim(img), []);
% Convert the grayscale image to an indexed image using the thermal colormap
[indexedImg, map] = gray2ind(I, 256); % Convert grayscale to indexed with 256 levels
map = thermal
I hope it helps to resolve your problem!
1 Comment
DGM
on 19 Feb 2024
Edited: DGM
on 19 Feb 2024
Note that imadjust() + gray2ind() won't result in the same quantization as imadjust() + imshow(). Neither will be the same as when using imagesc() or imshow(mat,[]).
% a color map
map = parula(16);
% an image on an arbitrary scale
A = repmat(linspace(-3.5,8.5,500),[80 1]);
% quantize using gray2ind()
B = gray2ind(mat2gray(A),size(map,1));
% capture the output of imagesc() just for comparison
imagesc(A)
colormap(map)
set(gca,'TickLength',[0 0]);
screenshot = frame2im(getframe(gca));
screenshot = imresize(screenshot,size(A),'nearest');
screenshot = im2double(screenshot);
clf
% compare gray2ind()'s quantization against imagesc()/imshow()
outpict = [ind2rgb(B,map); screenshot];
imshow(outpict,'border','tight')
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1621343/image.png)
Quantization alone aside, using imadjust() like this results in a (slightly) nonlinear mapping, since 2% of the data gets truncated.
The difference is probably moot considering the value of saving primary data in pseudocolor, but yes. OP is saving some sort of unknown integer intensity data and misrepresenting it as an index array for use with a completely unrelated color table of unknown length. If the camera is configured for Mono12 or Mono16 output, and the CT length is (e.g.) 256, then the result will just be a black image.
See Also
Categories
Find more on GenICam Interface in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!