Can't Open Image files?

4 ビュー (過去 30 日間)
Jennifer Diehl
Jennifer Diehl 2022 年 5 月 17 日
編集済み: DGM 2024 年 2 月 19 日
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
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
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.
For more details on rgb2ind you can refer https://www.mathworks.com/help/matlab/ref/rgb2ind.html
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
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')
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.

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by