📄 stegocombine.m
字号:
% force wolverine restored image color values to be between 0 and 255 wolverine_restored_big_image = uint8( wolverine_restored_big_image ); if DISPLAY_INTERMEDIATE_IMAGES % display the restored wolverine.jpg that is still the size of tree_path.jpg figure, imshow( wolverine_restored_big_image ); title( 'Restored Wolverine - Tree Path Size - Combined Image Resized' ); end % resize wolverine_restored_big_image to the size of the original wolverine.jpg wolverine_restored_image = imresize( wolverine_restored_big_image, [ original_wolverine_y_size , original_wolverine_x_size ] ); % display the restored wolverine image that is the original wolverine.jpg size figure, imshow( wolverine_restored_image ); title( 'Restored Wolverine - Original Size - Combined Image Resized' ); % compute the Peak Signal-to-Noise Ratio (PSNR) % Displayed in the Matlab command window mean_square_error = sum( sum( sum( ( original_wolverine_image - wolverine_restored_image ).^2 ) ) ) / double( original_wolverine_x_size * original_wolverine_y_size * 3 ); disp(' ') disp('The PSNR after resizing the combined image:') PSNR = 10 * log10( ( 255 )^2 / mean_square_error ) end % try to restore the wolverine image from the combined image when the % combined image is made a heavily compressed .jpg if (DISPLAY_TESTING_IMAGES == 2) || (DISPLAY_TESTING_IMAGES == 4) % accepts values 0 to 100 % even if you specify 100 Matlab will compress the image to a minor % degree, if you want absolutely no loss set PERCENT_OF_COMPRESSION % to 100 and add this line to the inside of the imwrite function: % , 'Mode', 'lossless' PERCENT_OF_COMPRESSION = 50; % uses Matlab to save the combined image as the compressed .jpg % image 'compressed_combined.jpg' imwrite( combined_image, 'combined_compressed.jpg', 'Quality', PERCENT_OF_COMPRESSION ); % reads in the compressed combined .jpg image restored_combined_image = uint8( imread( 'combined_compressed.jpg' ) ); if DISPLAY_INTERMEDIATE_IMAGES % display the compressed combined image .jpg image figure, imshow( restored_combined_image ); title( 'Combined Image - After Saving As a Compressed .jpg' ); end % try to get the original values in wolverine.jpg for x_value = 1:tree_path_x_size for y_value = 1:tree_path_y_size wolverine_restored_big_image( y_value, x_value, 1 ) = ( restored_combined_image( y_value, x_value, 1 ) - original_tree_path_image( y_value, x_value, 1 ) ) / WEIGHTED_COMBINE_VALUE; wolverine_restored_big_image( y_value, x_value, 2 ) = ( restored_combined_image( y_value, x_value, 2 ) - original_tree_path_image( y_value, x_value, 2 ) ) / WEIGHTED_COMBINE_VALUE; wolverine_restored_big_image( y_value, x_value, 3 ) = ( restored_combined_image( y_value, x_value, 3 ) - original_tree_path_image( y_value, x_value, 3 ) ) / WEIGHTED_COMBINE_VALUE; end end % force wolverine restored image color values to be between 0 and 255 wolverine_restored_big_image = uint8( wolverine_restored_big_image ); if DISPLAY_INTERMEDIATE_IMAGES % display the restored wolverine.jpg that is still the size of tree_path.jpg figure, imshow( wolverine_restored_big_image ); title( 'Restored Wolverine - Tree Path Size - Combined Image Saved As a Compressed .jpg' ); end % resize wolverine_restored_big_image to the size of the original wolverine.jpg wolverine_restored_image = imresize( wolverine_restored_big_image, [ original_wolverine_y_size , original_wolverine_x_size ] ); % display the restored wolverine image that is the original wolverine.jpg size figure, imshow( wolverine_restored_image ); title( 'Restored Wolverine - Original Size - Combined Image Saved As a Compressed .jpg' ); % compute the Peak Signal-to-Noise Ratio (PSNR) % Displayed in the Matlab command window mean_square_error = sum( sum( sum( ( original_wolverine_image - wolverine_restored_image ).^2 ) ) ) / double( original_wolverine_x_size * original_wolverine_y_size * 3 ); disp(' ') disp('The PSNR after compressing the combined image to a .jpg:') PSNR = 10 * log10( ( 255 )^2 / mean_square_error ) end % try to restore the wolverine image from the combined image when the % combined image has random added noise if (DISPLAY_TESTING_IMAGES == 3) || (DISPLAY_TESTING_IMAGES == 4) % specifies the maximum noise value MAX_NOISE_VALUE = 20; % specifies the approximate amount of noise % amount of noise = (1 / AMOUNT_OF_NOISE)% % 0 means every pixel of the combined image will have added noise % 1 means ~50% will have added noise, 2 means ~33%, 3 means ~25%, .... AMOUNT_OF_NOISE = 3; noise_image = uint8( zeros( tree_path_y_size, tree_path_x_size, 3 ) ); % create a random noise image for x_value = 1:tree_path_x_size for y_value = 1:tree_path_y_size if round( rand() * AMOUNT_OF_NOISE ) == 0 noise_image( y_value, x_value, 1 ) = round( rand() * (MAX_NOISE_VALUE + 1) ); noise_image( y_value, x_value, 2 ) = round( rand() * (MAX_NOISE_VALUE + 1) ); noise_image( y_value, x_value, 3 ) = round( rand() * (MAX_NOISE_VALUE + 1) ); end end end % add the noise image to the combined image noise_added_combined_image = combined_image + noise_image; if DISPLAY_INTERMEDIATE_IMAGES noise_display_image = ones( tree_path_y_size, tree_path_x_size, 3 ) * 255; % create a random noise image for x_value = 1:tree_path_x_size for y_value = 1:tree_path_y_size if noise_image( y_value, x_value, 1 ) ~= 0 noise_display_image( y_value, x_value, 1 ) = noise_image( y_value, x_value, 1 ); end if noise_image( y_value, x_value, 2 ) ~= 0 noise_display_image( y_value, x_value, 2 ) = noise_image( y_value, x_value, 2 ); end if noise_image( y_value, x_value, 3 ) ~= 0 noise_display_image( y_value, x_value, 3 ) = noise_image( y_value, x_value, 3 ); end end end % display the noise image figure, imshow( uint8(noise_display_image) ); title( 'Noise to Add to Combined Image' ); % display the combined image with added noise figure, imshow( restored_combined_image ); title( 'Combined Image - After Adding Noise' ); end % try to get the original values in wolverine.jpg for x_value = 1:tree_path_x_size for y_value = 1:tree_path_y_size wolverine_restored_big_image( y_value, x_value, 1 ) = ( noise_added_combined_image( y_value, x_value, 1 ) - original_tree_path_image( y_value, x_value, 1 ) ) / WEIGHTED_COMBINE_VALUE; wolverine_restored_big_image( y_value, x_value, 2 ) = ( noise_added_combined_image( y_value, x_value, 2 ) - original_tree_path_image( y_value, x_value, 2 ) ) / WEIGHTED_COMBINE_VALUE; wolverine_restored_big_image( y_value, x_value, 3 ) = ( noise_added_combined_image( y_value, x_value, 3 ) - original_tree_path_image( y_value, x_value, 3 ) ) / WEIGHTED_COMBINE_VALUE; end end % force wolverine restored image color values to be between 0 and 255 wolverine_restored_big_image = uint8( wolverine_restored_big_image ); if DISPLAY_INTERMEDIATE_IMAGES % display the restored wolverine.jpg that is still the size of tree_path.jpg figure, imshow( wolverine_restored_big_image ); title( 'Restored Wolverine - Tree Path Size - Combined Image With Added Noise' ); end % resize wolverine_restored_big_image to the size of the original wolverine.jpg wolverine_restored_image = imresize( wolverine_restored_big_image, [ original_wolverine_y_size , original_wolverine_x_size ] ); % display the restored wolverine image that is the original wolverine.jpg size figure, imshow( wolverine_restored_image ); title( 'Restored Wolverine - Original Size - Combined Image With Added Noise' ); % compute the Peak Signal-to-Noise Ratio (PSNR) % Displayed in the Matlab command window mean_square_error = sum( sum( sum( ( original_wolverine_image - wolverine_restored_image ).^2 ) ) ) / double( original_wolverine_x_size * original_wolverine_y_size * 3 ); disp(' ') disp('The PSNR after adding random noise to the combined image:') PSNR = 10 * log10( ( 255 )^2 / mean_square_error ) endend
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -