سلام، به این صورت می تونید بنویسید البته می تونید از printf به بعد را از داخل تابع حذف کنید
function [mse compressed_image] = iframe(img, zarib)
grayImg =double(rgb2gray(img));
DC = blkproc(grayImg, [8 8], @dct2);
Quantization_Matrix=...
[ 16 11 10 16 24 40 51 61;
12 12 14 19 26 58 60 55;
14 13 16 24 40 57 69 56;
14 17 22 29 51 87 80 62;
18 22 37 56 68 109 103 77;
24 35 55 64 81 104 113 92;
49 64 78 87 103 121 120 101;
72 92 95 98 112 100 103 99 ];
if zarib < 50
Quantization_Matrix = Quantization_Matrix * 50 / zarib ;
else
Quantization_Matrix = Quantization_Matrix * (100 - zarib) / 50;
end
Quantization_Matrix = double(uint8((Quantization_Matrix - .2) / 254.8 * 254 + 1));
quantized_DC = round(blkproc(DC, [8 8], @(x, y) x ./ y , Quantization_Matrix));
reconstructed_DC = blkproc(quantized_DC, [8 8], @(x, y) x .* y , Quantization_Matrix);
compressed_image = round(blkproc(reconstructed_DC, [8 8], @idct2));
mse =sum(( grayImg(:) - compressed_image(:)) .^ 2) / numel(grayImg);
printf("MSE = %f\n", mse)
figure;
subplot(2,2,1),imshow(grayImg,[0,255]);
subplot(2,2,2),imshow(compressed_image,[0,255]);
subplot(2,2,3),imhist(grayImg);
subplot(2,2,4),imhist(compressed_image);
end
این هم نحوه استفاده
img = imread ('cameraman.tif');
[mse compressed_image] = iframe(img, 1);