i am converting a RGB image to ycbcr image for processing. but when i try to convert the ycbcr image back to RGB image there is an error in the original image what should i do to remove or altease furthur reduce the image?

3 views (last 30 days)
clc
clear all;
close all;
RGB = imread('board.tif');%read image
ycbcr=rgb2ycbcr(RGB);%converting RGB image to Ycrcb color space
%\\extracting y,cb,cr planes saperately\\
test_ycbcr(:,:,1)=ycbcr(:,:,1);
test_ycbcr(:,:,2)=ycbcr(:,:,2);
test_ycbcr(:,:,3)=ycbcr(:,:,3);
%\\merging to form a new ycbcr image(same image in this case)and converting it to RGB color space\\
test_rgb=ycbcr2rgb(test_ycbcr);
%\\error calculation
error=(test_rgb-RGB).^2;
[m n o]=size(test_ycbcr);
MSE=sum(sum(sum(error)))/(m*n*o)
PSNR = 10 * log10( 255^2 / MSE)

Answers (1)

DGM
DGM on 7 May 2023
For a start, we can clean this up.
RGB = imread('board.tif'); % read image
% converting RGB image to YCbCr color space
ycbcr = rgb2ycbcr(RGB);
% duplicate the YCC image
% i'm assuming this is a placeholder for some other calculations
test_ycbcr = ycbcr;
% convert it to RGB color space
test_rgb = ycbcr2rgb(test_ycbcr);
% error calculation
MSE = immse(test_rgb,RGB)
MSE = 0.3560
PSNR = psnr(test_rgb,RGB)
PSNR = 52.6157
This error should be expected. See this thread, and all the comments for a discussion of the sources of the error, and see this answer for the only way to obtain a lossless round-trip conversion.
TL;DR: You aren't generally going to get a lossless round-trip conversion from RGB to YCbCr and back. You can do it in YCoCg or YCoCg-R, but those aren't YCbCr.

Categories

Find more on Convert Image Type in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!