How to save an image from GUI ?

1 Ansicht (letzte 30 Tage)
Gayatri B
Gayatri B am 26 Sep. 2019
Kommentiert: Gayatri B am 17 Okt. 2019
How to save an image which is generated in GUI and use it further in the same code ? I want to calculate MSE and PSNR values for an image which is generated in GUI but stuck in code that how to save it and use it further. Please help.
  2 Kommentare
Adam
Adam am 26 Sep. 2019
What do you mean by 'generated in GUI'? You must have code somewhere that generates the data.
should then help in terms of sharing that data to different callbacks where you may wish to use it.
Gayatri B
Gayatri B am 17 Okt. 2019
Hi, following is my code of my project and want to save the image which is generated in data hiding and want to use further. Can you help me in this ?
function varargout = Image_steganography(varargin)
% IMAGE_STEGANOGRAPHY MATLAB code for Image_steganography.fig
% IMAGE_STEGANOGRAPHY, by itself, creates a new IMAGE_STEGANOGRAPHY or raises the existing
% singleton*.
%
% H = IMAGE_STEGANOGRAPHY returns the handle to a new IMAGE_STEGANOGRAPHY or the handle to
% the existing singleton*.
%
% IMAGE_STEGANOGRAPHY('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in IMAGE_STEGANOGRAPHY.M with the given input arguments.
%
% IMAGE_STEGANOGRAPHY('Property','Value',...) creates a new IMAGE_STEGANOGRAPHY or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before Image_steganography_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to Image_steganography_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help Image_steganography
% Last Modified by GUIDE v2.5 22-Dec-2018 11:44:09
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Image_steganography_OpeningFcn, ...
'gui_OutputFcn', @Image_steganography_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before Image_steganography is made visible.
function Image_steganography_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to Image_steganography (see VARARGIN)
% Choose default command line output for Image_steganography
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes Image_steganography wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = Image_steganography_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in Retrive.
function Retrive_Callback(hObject, eventdata, handles)
% hObject handle to Retrive (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global l;
h=mod(l,2);
p=zeros(1000,1000);
for x=1:1000
for y=1:1000
if(h(x,y)==1)
p(x,y)=255;
end
end
end
s=im2bw(p);
axes(handles.axes4);
imshow(s);
grid on;
% --- Executes on button press in input_image.
function Cover_image_Callback(hObject, eventdata, handles)
% hObject handle to input_image (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global k;
i=imread('b.jpg');
j=imresize(i,[1000, 1000]); % resizing taken image
k=rgb2gray(j); % converting rgb image to gray image
%subplot(1,2,1)
axes(handles.axes1);
imshow(k);
grid on;
% --- Executes on button press in Cover_image.
function input_image_Callback(hObject, eventdata, handles)
% hObject handle to Cover_image (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global z;
x=imread('colorlable.jpg'); % image to be hidden
y=imresize(x,[1000, 1000]); % resizing hidden image
z=im2bw(y); % converting rbg to binary
%subplot(1,2,2);
axes(handles.axes2);
imshow(z) % displaying image to be hidden
grid on;
% --- Executes on button press in Data_Hiding.
function Data_Hiding_Callback(hObject, eventdata, handles)
% hObject handle to Data_Hiding (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global z;
global k;
global l;
z=double(z); % increasing range to double
r=double(k-mod(k,2)); % removal of LSB bits
l=uint8(r+z); % adding LSB bit from image to be hidden
axes(handles.axes3);
imshow(l)
grid on;
a=imread('colorlable.jpg');
[m,n,d]=size(a);
kmax=floor((m*n)/(m+n+1));
da=double(a);
U=zeros(m,m);S=zeros(m,n);V=zeros(n,n);e=zeros(kmax,d);cr=zeros(kmax,1);rmse=zeros(kmax,d);
for i=1:d
[U(:,:,i),S(:,:,i),V(:,:,i)]=svd(da(:,:,i));
end
for k=1:kmax
ca=zeros(m,n,d);
MSE=m*n/(k*(m+n+1));
fprintf('MSE value at %f.\n',MSE);
SNR =(10*log10((sum(m.^2)))/MSE);
fprintf('PSNR value at %4f.\n',SNR);
end
a=imread('a.jpg');
[m,n,d]=size(a);
kmax=floor((m*n)/(m+n+1));
da=double(a);
U=zeros(m,m);S=zeros(m,n);V=zeros(n,n);e=zeros(kmax,d);cr=zeros(kmax,1);rmse=zeros(kmax,d);
for i=1:d
[U(:,:,i),S(:,:,i),V(:,:,i)]=svd(da(:,:,i));
end
for k=1:kmax
ca=zeros(m,n,d);
cr(k)=m*n/(k*(m+n+1));
fprintf('MSE1 value at %f.\n',cr(k));
SNR =(10*log10((sum(m.^2)))/cr(k));
fprintf('PSNR1 value at %4f.\n',SNR);
end

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by