Search code examples
matlabrgbdithering

Matlab - After dithering, RGB image can't divide into R-G-B


I'm new in Matlab..

I have image with dimension 512x512x3 uint8. And I use 'dither' function like this :

[Myimagedither, Myimagedithermap] = rgb2ind(img, 16, 'dither'); 
imwrite(Myimagedither,Myimagedithermap,'step_4_RGB_D_U_16.tiff');

after that, I use imread to read the image like this :

new_img = imread('step_4_RGB_D_U_16.tiff');

but, after that dimension change into 512x512 unit8 only. I need to divide that image into R G B. Can anyone help me to solve this?


Solution

  • You need to read the map seperatly. Like this:

    [new_img new_img_map] = imread('step_4_RGB_D_U_16.tiff');
    

    And then convert the image into rgb using ind2rgb() and divide the colorchannels into 3 seperate image. Like this:

    new_img_RGB = ind2rgb(new_img,new_img_map);
    g1_16 = new_img_RGB(:,:,1);
    g2_16 = new_img_RGB(:,:,2);
    g3_16 = new_img_RGB(:,:,3);