Can't Open Image files?
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
Image Analyst
2022-5-18
Save I to a .mat file. Then attach the .mat file and the .tiff file with the paperclip icon.
回答(1 个)
prabhat kumar sharma
2024-2-19
编辑:prabhat kumar sharma
2024-2-19
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 个评论
DGM
2024-2-19
编辑:DGM
2024-2-19
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Convert Image Type 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!