function [ yuvimg ] = BUPT_format_converter() % Title: This function convert an image from colour to grey scale % Image created by Yun Bo % Convert matrix T = [0.257 0.504 0.098; -0.148 -0.291 0.439; 0.439 -0.368 -0.071]; %offset matrix offset = [16;128;128]; % read the rgb image and seperate R G B [I,w,h,level]=ppmread('./test_images/Lena512C_ASCII2014.ppm'); I=double(I); R=I(:,:,1); G=I(:,:,2); B=I(:,:,3); %map between RGB and YUV Y = T(1,1) .* R + T(1,2) .* G + T(1,3) .* B + offset(1); U = T(2,1) .* R + T(2,2) .* G + T(2,3) .* B + offset(2); V = T(3,1) .* R + T(3,2) .* G + T(3,3) .* B + offset(3); %get YVU output yuvimg = cat(3,Y,U,V); imwrite(yuvimg(:,:,1),'Lena_Y.jpg'); figure,imshow(yuvimg(:,:,1)); imwrite(yuvimg,'Lena_YUV.jpg'); figure,imshow(yuvimg); %transform YVU to RGB again Y=double(Y); U=double(U); V=double(V); RR = 1.164*(Y-16)+1.596*(V-128); GG = 1.164*(Y-16)-0.813*(V-128)-0.391*(U-128); BB = 1.164*(Y-16)+2.018*(U-128); RR = uint8(round(RR)); GG = uint8(round(GG)); BB = uint8(round(BB)); rgbimg = cat(3,RR,GG,BB); imwrite(rgbimg,'Lena_RGB.jpg'); figure,imshow(rgbimg); end这个代码无法显示yuvimg与yuvimg(:,:,1)),请帮我修改一下
时间: 2023-09-06 09:12:20 浏览: 107
BUPT_transform.zip_BUPT__BUPT_transform_bupt matlab
可以尝试在显示yuvimg时指定显示的范围,以及设置图像标题,如下所示:
```matlab
imshow(yuvimg(:,:,1), [0 255]);
title('Y Component of YUV Image');
figure, imshow(yuvimg);
title('YUV Image');
```
同样,在显示yuvimg(:,:,1)时也需要指定显示的范围和设置标题:
```matlab
imshow(yuvimg(:,:,1), [0 255]);
title('Y Component of YUV Image');
```
在imshow函数中,[0 255]表示显示的范围为0到255。
阅读全文