The MATLAB code is as follows:
Close All;clear all;clc;% key=1; The%key is used to set the proportions that need to be compressed to read into the original image original String,os the original image string [filename pathname]=uigetfile (' *.bmp;*.jpg;*.tif ',' original image. jpg '); Os=[pathname filename];o=imread (OS);% read-in modified string, RS modified string [FileName,PathName]=uiputfile ({' *.bmp ';' *.jpg ';' *.tif '},' post-attack image. jpg '); rs=[PathName FileName];%%%%%%%%%%%%% Set Compression ratio prompt={' input compression ratio% '};title=' compression ratio '; lines=1; def={'};Mya=inputdlg (Prompt,title,lines, def, 'on ');key11=[mya{1}];key=str2num (KEY11);%%%%%%%%%%%%Set the compression scale imwrite (O,RS,' JPEG ',' quality ', key);% read the file just written into Rr=imread (RS); subplot (1,2,1), Imshow (o);%,title (' original image '); Set (GCA,' Title ', Text (' String ',' original image ')) Subplot (1,2,2), Imshow (RR);%,title (' compress image '); Set (GCA,' Title ', Text (' String ', [Num2str (Key)'% compressed image ']))
JPG Image attack test code