Filter löschen
Filter löschen

Can't Open Image files?

5 Ansichten (letzte 30 Tage)
Jennifer Diehl
Jennifer Diehl am 17 Mai 2022
Bearbeitet: DGM am 19 Feb. 2024
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 Kommentar
Image Analyst
Image Analyst am 18 Mai 2022
Save I to a .mat file. Then attach the .mat file and the .tiff file with the paperclip icon.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

prabhat kumar sharma
prabhat kumar sharma am 19 Feb. 2024
Bearbeitet: prabhat kumar sharma am 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.
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 Kommentar
DGM
DGM am 19 Feb. 2024
Bearbeitet: DGM am 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')
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.

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by