I am trying to implement color combine function from a imaging software called metamorph in matlab.I have three uint16 bit files(R,G and B) .I need to convert them to 12 bit and then combine them into a RGB image.metamorph converts the 16-bit files to 12-bit and then creates the RGB image from the three 12-bit files.my code is as follows开发者_StackOverflow社区.I am not quite sure how to go about converting a 16-bit image file to 12-bit.
C1 = imread('metamorph/R.tif',3);
C2 = imread('metamorph/G.tif',3);
C3 = imread('metamorph/B.tif',3);
R=mat2gray(C1);
G=mat2gray(C2);
B=mat2gray(C3);
rgb1=cat(3,R,G,B);
imshow(rgb1)
any help is greatly appreciated.
Thanks
I don't think MATLAB has a data type for 12 bit (which would be one-and-a-half byte per color per pixel). Of course you can scale you double data to fit into a 12 bit integer:
rgb12= round(rgb1/max(rgb1(:))*(2^12-1)); %# scale & round image values to 12 bit
... but then the real question is what good does that do:
- do you want to export to some 12bit RGB file format?
imwrite
can apparently do 12bit JPEG, but I'm unsure if that is 12 bit per color. - or do you want to save RAM while in MATLAB? In this case I'm not sure there is a sensible way to do that.
精彩评论