From: Ömer KAYA on
Hello All;

I am trying to export my 16bit one bant tif image to 16 bit color depth jpeg file. I used

A = imread('filename');

imwrite(A,'filename.jpg' , 'jpg');

bu in return it gave me Unit must be specified to 12 or 16 bit.

Can someone show me how to do ?

Regards

Ömer KAYA
From: ImageAnalyst on
I don't know what "bant" is, you didn't send in the 'BitDepth'
parameter into imwrite().
But anyway, 16 bit jpegs are only supported in monochrome in
imwrite(), not color.
I got this error message when I tried:
??? Error using ==> writejpg at 63
Only grayscale images supported with 16 bit data.



clc;
close all;
workspace;
fontSize = 14;

% Change the current folder to the folder of this m-file.
% (The line of code below is from Brett Shoelson of The Mathworks.)
if(~isdeployed)
cd(fileparts(which(mfilename)));
end

peaksImage = peaks(600);
maxValueFor16Bit = double(intmax('uint16'));
A = uint16(maxValueFor16Bit * (peaksImage - min(min(peaksImage))) /
(max(max(peaksImage)) - min(min(peaksImage))));
% Make some crazy, arbitrary 16 bit color image.
rgb16BitImage = cat(3, A, A', flipud(A));

% Extract the individual color planes.
redPlane = rgb16BitImage(:, :, 1);
greenPlane = rgb16BitImage(:, :, 2);
bluePlane = rgb16BitImage(:, :, 3);

subplot(2,4,1);
imshow(rgb16BitImage);
subplot(2,4,2);
imshow(redPlane, []);
subplot(2,4,3);
imshow(greenPlane, []);
subplot(2,4,4);
imshow(bluePlane, [])

set(gcf, 'Position', get(0,'Screensize')); % Maximize figure.

% Save it to a file
imwrite(rgb16BitImage, '16BitColorJPEGImage.jpg', 'BitDepth', 16);
% Recall it.
recalledImage = imread('16BitColorJPEGImage.jpg');
% See what it's class is.
class(recalledImage)