Reduce the image size while maintaining the quality. Use dct2 with RGB image. when I Concatenate the RGB I get white image
1 view (last 30 days)
Show older comments
% import image
pic=imread('image3.jpg');
size_a=size(pic)
imshow(pic);
% The image size is 2448x3264x3
% split RGB channels
[R,G,B]=imsplit(pic);
% apply DCT to each channel
DCTR=dct2(R);
DCTG=dct2(G);
DCTB=dct2(B);
% obtain the upper left corner of DCT to keep important values
[n1,n2]=size(DCTR)
picR=DCTR(1:round(n1/2),1:round(n2/2));
picG=DCTG(1:round(n1/2),1:round(n2/2));
picB=DCTG(1:round(n1/2),1:round(n2/2));
% perform inverse of DCT on all channels
R1=idct2(picR);
G1=idct2(picG);
B1=idct2(picB);
% combine RGB channels
rgbImage=cat(3,R1,G1,B1)
imshow(rgbImage,[])
size(rgbImage)
0 Comments
Answers (2)
Mahesh Taparia
on 19 Mar 2020
Hi
The image get converted to double format, convert back to uint8 format to show correctly. For example:
imshow(uint8(rgbImage));
0 Comments
Image Analyst
on 19 Mar 2020
Unlike gray scale images, you can't use [] with RGB images at all (it will just ignore them if you do). Also, if the RGB values are doubles and in the range 0-1, it will work. If they're outside that range you'll either have to scale it to that range with rescale() or mat2gray(), OR convert to uint8 in the range 0-255. Here's a little demo of some of the possibilities:
% Make double image in the range 0-3000
grayImage = 3000 * rand(100, 100, 3);
imshow(grayImage, []); % Works
% Make image in the range 0-255
rgbImage = 250 * rand(100, 100, 3);
imshow(rgbImage, []); % Doesn't work
% Make double image in the range 0-5000 and convert to uint8
rgbImage = uint8(255 * mat2gray(5000 * rand(100, 100, 3)));
imshow(rgbImage); % Works
% Make image in the range 0-65535 and convert to uint16
rgbImage = uint16(65535 * rand(100, 100, 3));
imshow(rgbImage); % Doesn't work
% Make image in the range 0-5000 and convert to uint8
rgbImage = im2uint8(5000 * rand(100, 100, 3));
imshow(rgbImage); % Doesn't work
% Make image in the range 0-1
rgbImage = 0.95 * rand(100, 100, 3);
imshow(rgbImage, []); % works
0 Comments
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!