Convert RGB image into 8 bit rgb image

32 visualizaciones (últimos 30 días)
Sajid Afaque
Sajid Afaque el 10 de Oct. de 2022
Comentada: Sajid Afaque el 11 de Oct. de 2022
hello,
I have an RGB image (example enclosed - imfinfo suggest its 24 bit image)
Now i need to convert this to an 8 bit RGB image.
How do i do it ?
when i googled this issue i learnt that to reduce the bit i have to divide by 256 but when i use 'imread' the pixels are divided into 3 individual (R,G & B)
  2 comentarios
Chunru
Chunru el 10 de Oct. de 2022
Your image has RGB channels and each channel is 8-bit uint. What do you want to do with the image? Do you mean 256 color-mapped image (8-bit per pixel)?
Sajid Afaque
Sajid Afaque el 10 de Oct. de 2022
Editada: Sajid Afaque el 10 de Oct. de 2022
yeah,
Forget the image i have attached,
Now imagine i have an 16 bit RGB image, How do i convert it to 8 bit RGB image ?(8 bit per pixel)

Iniciar sesión para comentar.

Respuesta aceptada

Chunru
Chunru el 10 de Oct. de 2022
Editada: Chunru el 10 de Oct. de 2022
im = imread("https://www.mathworks.com/matlabcentral/answers/uploaded_files/1150855/my_image.jpg");
[x,cmap] = rgb2ind(im,256);
imwrite(x, cmap, 'new_im.tif')
imfinfo('new_im.tif')
ans = struct with fields:
Filename: '/users/mss.system.sxxsXm/new_im.tif' FileModDate: '10-Oct-2022 08:44:00' FileSize: 28789400 Format: 'tif' FormatVersion: [] Width: 6485 Height: 4913 BitDepth: 8 ColorType: 'indexed' FormatSignature: [73 73 42 0] ByteOrder: 'little-endian' NewSubFileType: 0 BitsPerSample: 8 Compression: 'PackBits' PhotometricInterpretation: 'RGB Palette' StripOffsets: [8 448141 898960 1356409 1819783 2271388 2721773 3170526 3613626 4052208 4491269 4929518 5364482 5810260 6255633 6694416 7129850 7571051 8012049 8455557 8890185 9321557 9744499 10164448 10585440 11026774 11476633 … ] SamplesPerPixel: 1 RowsPerStrip: 76 StripByteCounts: [448133 450819 457449 463374 451605 450385 448753 443100 438582 439061 438249 434964 445778 445373 438783 435434 441201 440998 443508 434628 431372 422942 419949 420992 441334 449859 440535 437577 438804 450355 457902 … ] XResolution: 72 YResolution: 72 ResolutionUnit: 'Inch' Colormap: [256×3 double] PlanarConfiguration: 'Chunky' TileWidth: [] TileLength: [] TileOffsets: [] TileByteCounts: [] Orientation: 1 FillOrder: 1 GrayResponseUnit: 0.0100 MaxSampleValue: 255 MinSampleValue: 0 Thresholding: 1 Offset: 28787142
dir
. .. new_im.tif
  3 comentarios
Chunru
Chunru el 10 de Oct. de 2022
It seems that jpg use 24 bitdepth. Use tif format as updated above.
Sajid Afaque
Sajid Afaque el 11 de Oct. de 2022
Thanks @Chunru.
If possible can you please explain me how can i analytically see this conversion from 24-bit to 8bit.
what exactly happens in the below line of code
[x,cmap] = rgb2ind(im,256);

Iniciar sesión para comentar.

Más respuestas (0)

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by