%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Find the start time offset based on the cyclic prefix
%
% This method is immune to the issues that plague the ZC sequences (frequency offset causes a time shift in the
% correlation results)
%
% It's best to provide this function an upsampled copy of the burst to help fix any fractional time offset that might be
% present
%
% @param samples Complex IQ samples that make up the full burst
% @param sample_rate Sample rate (in Hz) of the provided samples
% @return start_offset Sample index that the burst starts at (first sample of the first cyclic prefix)
function [start_offset] = find_sto_cp(samples, sample_rate)
    [long_cp_len, short_cp_len] = get_cyclic_prefix_lengths(sample_rate);
    fft_size = get_fft_size(sample_rate);
    cyclic_prefix_length_schedule = [...
        long_cp_len, ...
        short_cp_len, ...
        short_cp_len, ...
        short_cp_len, ...
        short_cp_len, ...
        short_cp_len, ...
        short_cp_len, ...
        short_cp_len, ...
        long_cp_len];
    num_ofdm_symbols = length(cyclic_prefix_length_schedule);

    full_burst_len = sum(cyclic_prefix_length_schedule) + (fft_size * num_ofdm_symbols);
    num_tests = length(samples) - full_burst_len;
    scores_cp_sto = zeros(1, num_tests);

    for idx=1:num_tests
        offset = idx;
        scores = zeros(1, num_ofdm_symbols);

        % Extract and correlate the samples that each cyclic prefix is expected
        % to be at
        for cp_idx=1:num_ofdm_symbols
            cp_len = cyclic_prefix_length_schedule(cp_idx);

            % Extract the full OFDM symbol including cyclic prefix
            window = samples(offset:offset + fft_size + cp_len - 1);

            % Extract the cyclic prefix and the final samples of the symbol
            left = window(1:cp_len);
            right = window(end - cp_len + 1:end);

            % Correlate the two windows
            scores(cp_idx) = abs(xcorr(left, right, 0));

            % Move the sample pointer forward by the full symbol size
            offset = offset + cp_len + fft_size;
        end

        % In the real DroneID the first OFDM symbol needs to be ignored since
        % it isn't always present.  So, just average the correlation scores of
        % all but the first element
        scores_cp_sto(idx) = sum(scores(2:end)) / (length(scores) - 1);

    end

    % Find the index of the highest score
    [~, start_offset] = max(scores_cp_sto);
end


text:
function LMinstall(varargin)
%
% Downloads a set of folders from the LabelMe dataset. This function can be
% called in several ways depending on how do you want to specify the images
% that you want to download. If there is already a copy of the database in
% the local machine, it will only download the images that have not been
% yet downloaded. If the download breaks, there will be no need to download
% everything again. The annotations will be always downloaded even if they
% are already in the local machine.
%
% 1) Install all the images into the local paths: HOMEIMAGES, HOMEANNOTATIONS
%  LMinstall(HOMEIMAGES, HOMEANNOTATIONS);
%
% 2) install only images in the specified folders
%  LMinstall(folderlist, HOMEIMAGES, HOMEANNOTATIONS);
%
% 3) install only the images specified
%  LMinstall(foldername, filename, HOMEIMAGES, HOMEANNOTATIONS);
%
% 4)  LMinstall(D)
%  or LMinstall(D, HOMEIMAGES, HOMEANNOTATIONS)
%
% 5) install into a flat folder: this will destroy the folder structures
%      and it will copy all the images into a single level folder.
%  LMinstall(..., 'flat');
%
%
% HOMEIMAGES and HOMEANNOTATIONS point to your local destination folders.
% If they are not specified, then the data will be downloaded into the
% current path.
%
% This function is useful if you do not want to download the entire
% dataset. You can first browse the dataset, and when you have decided for
% a set of folders that you want to use, you can use this function to
% download only those folders.
%
% Contribute to the dataset by labeling few images:
% http://labelme.csail.mit.edu/
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% LabelMe is a WEB-based image annotation tool and a Matlab toolbox that allows
% researchers to label images and share the annotations with the rest of the community.
%    Copyright (C) 2007  MIT, Computer Science and Artificial
%    Intelligence Laboratory. Antonio Torralba, Bryan Russell, William T. Freeman
%
%    This program is free software: you can redistribute it and/or modify
%    it under the terms of the GNU General Public License as published by
%    the Free Software Foundation, either version 3 of the License, or
%    (at your option) any later version.
%
%    This program is distributed in the hope that it will be useful,
%    but WITHOUT ANY WARRANTY; without even the implied warranty of
%    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%    GNU General Public License for more details.
%
%    You should have received a copy of the GNU General Public License
%    along with this program.  If not, see <http://www.gnu.org/licenses/>.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% If this function stops working, you might need to download the newest
% version of the toolbox in order to update the web addresses:

webpageanno = 'http://labelme.csail.mit.edu/Annotations';
webpageimg = 'http://labelme.csail.mit.edu/Images';

Narguments = length(varargin);

if strcmp(varargin{Narguments}, 'flat')
    flat = 1;
    Narguments = Narguments - 1;
else
    flat = 0; % keep original folder structure
end

switch Narguments
    case {0}
        error('Not enough input arguments.')
    case {1}
        HOMEIMAGES = 'labelme/images';
        HOMEANNOTATIONS = 'labelme/annotations';
    case 2
        disp('Install full database')
        HOMEIMAGES = varargin{1};
        HOMEANNOTATIONS = varargin{2};
        folderlist = urldir(webpageimg, 'DIR');
        folderlist = {folderlist(:).name};
        if strcmp(folderlist{1}(1),'/'); % remove root folder
            folderlist = folderlist(2:end);
        end
    case 3
        folderlist = varargin{1};
        HOMEIMAGES = varargin{2};
        HOMEANNOTATIONS = varargin{3};
    case 4
        folders = varargin{1};
        filelist = varargin{2};
        folderlist = unique(folders);
        HOMEIMAGES = varargin{3};
        HOMEANNOTATIONS = varargin{4};
    case 5
        folders = varargin{1};
        folderlist = unique(folders);
        HOMEIMAGES = varargin{2};
        HOMEANNOTATIONS = varargin{3};
        webpageimg = varargin{4};
        webpageanno = varargin{5};
    case 6
        folders = varargin{1};
        folderlist = unique(folders);
        filelist = varargin{2};
        HOMEIMAGES = varargin{3};
        HOMEANNOTATIONS = varargin{4};
        webpageimg = varargin{5};
        webpageanno = varargin{6};
end

% if the first argument was a struct, then we need to change the image
% lists to:
if isstruct(varargin{1})
    clear folders folderlist filelist
    D = varargin{1};
    for i = 1:length(D)
        folders{i} = D(i).annotation.folder;
        filelist{i} = D(i).annotation.filename;
    end
    folderlist = unique(folders);
end

Nfolders = length(folderlist);

% create folders:
if flat == 0
    disp('Create folders');
    for i = 1:Nfolders
        disp(folderlist{i})
        mkdir(HOMEIMAGES, folderlist{i});
        mkdir(HOMEANNOTATIONS, folderlist{i});
    end
else
    disp('Flat mode: all images and annotation will be copied into a single level folder each')
    mkdir(HOMEIMAGES);
    mkdir(HOMEANNOTATIONS);
end

disp('download images and annotations...')
for f = 1:Nfolders
    disp(sprintf('Downloading folder %s (%d/%d)...',  folderlist{f}, f, Nfolders))

    wpi = [webpageimg  '/' folderlist{f}];
    wpa = [webpageanno '/' folderlist{f}];

    if ismember(Narguments, [2 3 5])
        images = urldir(wpi, 'img');
        if ~isempty(images)
            images = {images(:).name};
        end

        annotations = urldir(wpa, 'txt');
        if ~isempty(annotations)
            annotations = {annotations(:).name};
        end
    else
        j = strmatch(folderlist{f}, folders, 'exact');
        images = filelist(j);
        annotations = strrep(filelist(j), '.jpg', '.xml');
    end

    Nimages = length(images);
    for i = 1:Nimages
        fp = fopen(fullfile(HOMEIMAGES,folderlist{f}, images{i}));

        if fp < 0
			disp(sprintf('    Downloading image %s (%d/%d)...',  images{i}, i, Nimages))
            if flat == 0
                [F,STATUS] = urlwrite([wpi '/' images{i}], fullfile(HOMEIMAGES, folderlist{f}, images{i}));
            else
                [F,STATUS] = urlwrite([wpi '/' images{i}], fullfile(HOMEIMAGES, images{i}));
            end
        else
            fclose(fp);
            disp(sprintf('no need to download again: %s', images{i}))
		end
    end

    Nanno= length(annotations);
    for i = 1:Nanno
        disp(sprintf('    Downloading annotation %s (%d/%d)...',  annotations{i}, i, Nanno))
        if flat == 0
            [F,STATUS] = urlwrite([wpa '/' annotations{i}], fullfile(HOMEANNOTATIONS,folderlist{f},annotations{i}));
        else
            [F,STATUS] = urlwrite([wpa '/' annotations{i}], fullfile(HOMEANNOTATIONS,annotations{i}));
        end
        if STATUS == 0
            disp(sprintf('annotation file %s does not exist', annotations{i}))
        end
    end
end

author: CSAILVision

repo: LabelMeToolbox


text:
function [V, Qpv, Sf, St, Sslack, iter, success] = calc_v_pq_sum(Vslack,nb,nl,f,Zb,Ybf,Ybt,Yd,Sd,pv,Pg,Vg,mpopt)
%CALC_V_PQ_SUM  Solves the power flow using the power summation method.
%
%   [V, Qpv, Sf, St, Sslack, iter, success] = calc_v_pq_sum(Vslack,nb,nl,f,Zb,Ybf,Ybt,,Yd,Sd,pv,Pg,Vg,tol,iter_max)
%
%   Solves for bus voltages, generator reactive power, branch active and
%   reactive power flows and slack bus active and reactive power. The input
%   data consist of slack bus voltage, vector "from bus" indices, branch
%   impedance and shunt admittance, vector of bus shunt admittances and
%   load demand, as well as vectors with indicies of PV buses with their
%   specified voltages and active powers. It is assumed that the branches
%   are ordered using the principle of oriented ordering: indicies of
%   sending nodes are smaller then the indicies of the receiving nodes. The
%   branch index is equal to the index of their receiving node. Branch
%   addmittances are added in Yd and treated as constant admittance bus
%   loads. The applied method is Voltage correction power flow (VCPF) taken
%   from:
%   D. Rajicic, R. Ackovski and R. Taleski, "Voltage correction power flow,"
%   IEEE Transactions on Power Delivery, vol. 9, no. 2, pp. 1056-1062, Apr 1994.
%   https://doi.org/10.1109/61.296308
%
%   See also RADIAL_PF.

%% initialize
tol      = mpopt.pf.tol;
iter_max = mpopt.pf.radial.max_it;
vcorr    = mpopt.pf.radial.vcorr == 1;
Sd(pv) = Sd(pv) - Pg;
V = Vslack * ones(nb,1);
Vold = V;
iter = 0;
success = 0;
% ZIP load model
pw = mpopt.exp.sys_wide_zip_loads.pw;
qw = mpopt.exp.sys_wide_zip_loads.qw;
if isempty(pw)
    pw = [1 0 0];
end
if isempty(qw)
    qw = pw;
end
Sdz = real(Sd) * pw(3) + 1j * imag(Sd) * qw(3); % constant impedance
Sdi = real(Sd) * pw(2) + 1j * imag(Sd) * qw(2); % constant current
Sdp = real(Sd) * pw(1) + 1j * imag(Sd) * qw(1); % constant power
% Add artificial branch at the top of the branch list, so that the branch
% index for other branches is equal to the index of their receiving node.
 f = [0; f];
Zb = [0; Zb];
nl = nl + 1;
%% make Zpv matrix, for calculation of the PV generators reactive powers
if ~isempty(pv)
    Zpv = make_zpv(pv,nb,nl,f,Zb,Yd);
    Bpv = (imag(Zpv))^-1;
end
npv = length(pv);
Qpv = zeros(npv,1);
%% do backward-forward iterations
if mpopt.verbose > 1
    fprintf('\n it    max V mismatch (p.u.)');
    fprintf('\n----  ----------------------');
end
while success == 0 && iter < iter_max
    iter = iter + 1;
    % calculate load demand using actual voltages
    Vm = abs(V);
    S = Sdp + Sdi.*Vm + Sdz.*Vm.^2 + conj(Yd).*Vm.^2;
    % backward sweep
    St = S;
    Sf = St;
    for k = nl:-1:2
        i = f(k);
        Sf(k) = St(k) + Zb(k) * abs(St(k)/V(k))^2;
        St(i) = St(i) + Sf(k);
    end
    % forward sweep
    for k = 2:nl
        i = f(k);
        V(k) = V(i) - Zb(k) * conj(Sf(k)/V(i));
    end
    % check for convergence
    DU = abs(V - Vold);
    DU(isnan(DU)) = inf;
    if mpopt.verbose > 1
        fprintf('\n%3d        %10.3e', iter, max(DU));
    end
    if max(DU) > tol
        Vold = V;
        % update PV generators reactive powers
        if ~isempty(pv)
            DE = (Vg./abs(V(pv))-1).*real(V(pv)); % Rajicic (VCPF)
            DD = Bpv * DE;
            if vcorr
                DC = DD .* imag(V(pv))./real(V(pv));
                V_corr = make_vcorr(DC+1j*DD,pv,nb,nl,f,Zb);
                V = V + V_corr;
            end
            DQ = DD .* abs(V(pv)).^2 ./ real(V(pv));
            Qpv = Qpv + DQ;
            Sdp(pv) = Sdp(pv) - 1j*DQ;
        end
    else
        success = 1;
    end
end
if mpopt.verbose
    if success
        fprintf('\nPower summation converged in %d iterations.\n', iter);
    else
        fprintf('\nPower summation did not converge in %d iterations.\n', iter);
    end
end
%% calculate branch flows
% take out the first artificial branch
Sslack = St(1);
Sf = Sf(2:end);
St = St(2:end);
f = f(2:end);
% correct branch flows to account for branch shunt admittances
Sf = Sf + conj(Ybf) .* abs(V(f)).^2;
St = St - conj(Ybt) .* abs(V(2:end)).^2;

author: MATPOWER

repo: matpower

save_path: github-repos/MATLAB/MATPOWER-matpower


text:
function centroid = triangle_centroid_3d ( t )

%*****************************************************************************80
%
%% TRIANGLE_CENTROID_3D computes the centroid of a triangle in 3D.
%
%  Discussion:
%
%    The centroid of a triangle can also be considered the
%    center of gravity or center of mass, assuming that the triangle
%    is made of a thin uniform sheet of massy material.
%
%    The centroid of a triangle is the intersection of the medians.
%    A median of a triangle is a line connecting any vertex to the
%    midpoint of the opposite side.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    30 January 2005
%
%  Author:
%
%    John Burkardt
%
%  Parameters:
%
%    Input, real T(3,3), the triangle vertices.
%
%    Output, real CENTROID(3,1), the coordinates of the centroid.
%
  dim_num = 3;

  for i = 1 : dim_num
    centroid(i,1) = sum ( t(i,1:3) ) / 3.0;
  end

  return
end

author: johannesgerer

repo: jburkardt-m


text:
D = 2; % we consider a two-dimensional problem
N = 100; % we will generate 100 observations

%% Generate a random Covariance matrix
tmp = randn(D);
Sigma = tmp.' * tmp;

%% Sample from the corresponding Gaussian
X = mvnrnd(zeros(D, 1), Sigma, N);

%% Estimate the leading component
comp = grassmann_average(M, 1); % the second input is the number of component to estimate
comp = trimmed_grassmann_average(M', 50, 1);
show_2dvideo(comp,m,n);
show_2dvideo(comp(:,1),m,n);
show_2dvideo(comp(:,2),m,n);
show_2dvideo(comp(:,3),m,n);
show_2dvideo(comp(:,4),m,n);
show_2dvideo(comp(:,5),m,n);

%% Plot the results
plot(X(:, 1), X(:, 2), 'ko', 'markerfacecolor', [255,153,51]./255);
axis equal
hold on
plot(3*[-comp(1), comp(1)], 3*[-comp(2), comp(2)], 'k', 'linewidth', 2)
hold off
axis off

author: andrewssobral

repo: lrslibrary


text:
function sS = subSet(sS,ind)
% subindex vector3d

sS.b = sS.b(ind);
sS.l = sS.l(ind);
sS.u = sS.u(ind);

end

author: mtex-toolbox

repo: mtex

save_path: github-repos/MATLAB/mtex-toolbox-mtex


text:
function varargout = C_ImagebProcessing(varargin)
% C_IMAGEBPROCESSING MATLAB code for C_ImagebProcessing.fig
%      C_IMAGEBPROCESSING, by itself, creates a new C_IMAGEBPROCESSING or raises the existing
%      singleton*.
%
%      H = C_IMAGEBPROCESSING returns the handle to a new C_IMAGEBPROCESSING or the handle to
%      the existing singleton*.
%
%      C_IMAGEBPROCESSING('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in C_IMAGEBPROCESSING.M with the given input arguments.
%
%      C_IMAGEBPROCESSING('Property','Value',...) creates a new C_IMAGEBPROCESSING or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before C_ImagebProcessing_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to C_ImagebProcessing_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 C_ImagebProcessing

% Last Modified by GUIDE v2.5 17-Jun-2012 17:30:40

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @C_ImagebProcessing_OpeningFcn, ...
                   'gui_OutputFcn',  @C_ImagebProcessing_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 C_ImagebProcessing is made visible.
function C_ImagebProcessing_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 C_ImagebProcessing (see VARARGIN)

% Choose default command line output for C_ImagebProcessing
handles.output = hObject;

set(handles.g1,'Visible','off');
set(handles.g2,'Visible','off');
set(handles.dim,'Enable','off');
set(handles.path,'Enable','off');
set(handles.save,'Enable','off');
set(handles.s1,'Enable','off');
set(handles.s2,'Enable','off');
set(handles.s3,'Enable','off');
set(handles.s4,'Enable','off');
set(handles.g3,'Visible','off');
set(handles.g4,'Visible','off');
set(handles.s5,'Enable','off');
set(handles.s6,'Enable','off');
set(handles.s7,'Enable','off');
set(handles.s8,'Enable','off');
set(handles.s9,'Enable','off');
set(handles.slider1,'Enable','off');
set(handles.slider2,'Enable','off');
set(handles.slider3,'Enable','off');
set(handles.slider4,'Enable','off');
set(handles.slider5,'Enable','off');
set(handles.set1,'Enable','off');
set(handles.set2,'Enable','off');
set(handles.set3,'Enable','off');
set(handles.set4,'Enable','off');
set(handles.set5,'Enable','off');
set(handles.rv,'Enable','off');
set(handles.gv,'Enable','off');
set(handles.bv,'Enable','off');
set(handles.cv,'Enable','off');
set(handles.bbv,'Enable','off');
set(handles.reset,'Enable','off');
set(handles.e1,'Enable','off');
set(handles.e2,'Enable','off');
set(handles.resize,'Enable','off');
set(handles.chres,'Enable','off');
set(handles.sres,'Enable','off');
set(handles.set5,'Enable','off');
set(handles.rrv,'Enable','off');
set(handles.slider6,'Enable','off');
set(handles.s10,'Enable','off');
set(handles.s6,'Enable','off');
set(handles.p1,'Enable','off');
set(handles.p2,'Enable','off');
set(handles.p3,'Enable','off');
set(handles.p4,'Enable','off');
set(handles.p5,'Enable','off');
set(handles.p6,'Enable','off');
set(handles.p7,'Enable','off');
set(handles.selectcm,'Enable','off');
set(handles.setcm,'Enable','off');
set(handles.invc,'Enable','off');
set(handles.autoa,'Enable','off');
set(handles.rgbo,'Enable','off');
set(handles.rgbm,'Enable','off');
set(handles.autocon,'Enable','off');
set(handles.crop,'Enable','off');
set(handles.n1,'Enable','off');
set(handles.n3,'Enable','off');
set(handles.n4,'Enable','off');
set(handles.n5,'Enable','off');
set(handles.dim2,'Enable','off');
set(handles.info,'Enable','off');
set(handles.f1,'Enable','off');
set(handles.f2,'Enable','off');
set(handles.f3,'Enable','off');
set(handles.f4,'Enable','off');
set(handles.dia,'Enable','off');
set(handles.ero,'Enable','off');
set(handles.strel,'Enable','off');
set(handles.strels,'Enable','off');
set(handles.strelv,'Enable','off');
set(handles.dfh1,'Enable','off');
set(handles.dfh2,'Enable','off');
% Update handles structure

guidata(hObject, handles);

% UIWAIT makes C_ImagebProcessing wait for user response (see UIRESUME)
% uiwait(handles.figure1);

% --- Outputs from this function are returned to the command line.
function varargout = C_ImagebProcessing_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;

function updateg4(handles)
r=handles.img(:,:,1);
g=handles.img(:,:,2);
b=handles.img(:,:,3);
x=size(r); x=(1:x(1,2));
r=r(1,:); g=g(1,:); b=b(1,:);
axes(handles.g4); plot(x,r,'r');
hold on
plot(x,g,'g'); plot(x,b,'b'); hold off;

% --- Executes on button press in load.
function load_Callback(hObject, eventdata, handles)
% hObject    handle to load (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Browse the file from user
[file path]=uigetfile({'*.jpg';'*.bmp';'*.jpeg';'*.png'}, 'Load Image File within Avilable Extensions');
image=[path file];
handles.file=image;
if (file==0)
    warndlg('You did not selected any file ') ; % fille is not selected
end
 [fpath, fname, fext]=fileparts(file);
 validex=({'.bmp','.jpg','.jpeg','.png'});
 found=0;
 for (x=1:length(validex))
 if (strcmpi(fext,validex{x}))
     found=1;
     set(handles.dim,'Enable','on');
set(handles.path,'Enable','on');
set(handles.save,'Enable','on');
set(handles.s1,'Enable','on');
set(handles.s2,'Enable','on');
set(handles.s3,'Enable','on');
set(handles.s4,'Enable','on');
set(handles.s5,'Enable','on');
set(handles.s6,'Enable','on');
set(handles.s7,'Enable','on');
set(handles.s8,'Enable','on');
set(handles.s9,'Enable','on');
set(handles.slider1,'Enable','on');
set(handles.slider2,'Enable','on');
set(handles.slider3,'Enable','on');
set(handles.slider4,'Enable','on');
set(handles.slider5,'Enable','on');
set(handles.set1,'Enable','on');
set(handles.set2,'Enable','on');
set(handles.set3,'Enable','on');
set(handles.set4,'Enable','on');
set(handles.set5,'Enable','on');
set(handles.rv,'Enable','on');
set(handles.gv,'Enable','on');
set(handles.bv,'Enable','on');
set(handles.cv,'Enable','on');
set(handles.bbv,'Enable','on');
set(handles.reset,'Enable','on');
set(handles.e1,'Enable','on');
set(handles.e2,'Enable','on');
set(handles.resize,'Enable','on');
set(handles.chres,'Enable','on');
set(handles.sres,'Enable','on');
set(handles.set5,'Enable','on');
set(handles.rrv,'Enable','on');
set(handles.slider6,'Enable','on');
set(handles.s10,'Enable','on');
%set(handles.g2,'Visible','on');
set(handles.p1,'Enable','on');
set(handles.p2,'Enable','on');
set(handles.p3,'Enable','on');
set(handles.p4,'Enable','on');
set(handles.selectcm,'Enable','on');
set(handles.setcm,'Enable','on');
set(handles.invc,'Enable','on');
set(handles.autoa,'Enable','on');
set(handles.rgbo,'Enable','on');
set(handles.rgbm,'Enable','on');
set(handles.autocon,'Enable','on');
set(handles.crop,'Enable','on');
set(handles.n1,'Enable','on');
set(handles.n3,'Enable','on');
set(handles.n4,'Enable','on');
set(handles.n5,'Enable','on');
set(handles.dim2,'Enable','on');
set(handles.info,'Enable','on');
set(handles.f1,'Enable','on');
set(handles.f2,'Enable','on');
set(handles.f3,'Enable','on');
set(handles.f4,'Enable','on');
set(handles.dia,'Enable','on');
set(handles.ero,'Enable','on');
set(handles.strel,'Enable','on');
set(handles.strels,'Enable','on');
set(handles.strelv,'Enable','on');
set(handles.dfh1,'Enable','on');
set(handles.dfh2,'Enable','on');

     handles.img=imread(image);
handles.i=imread(image);
h = waitbar(0,'Please wait...');
steps = 100;
for step = 1:steps
    % computations take place here
    waitbar(step / steps)
end
close(h)
 axes(handles.g1); cla; imshow(handles.img);
 axes(handles.g2); cla; imshow(handles.img);
 [dimen]=size(handles.img); dimen=num2str(dimen); set(handles.dim,'String',dimen);
 s=num2str(size(handles.img)); set(handles.dim2,'String',s);
 set(handles.path,'String',image);
 guidata(hObject,handles);
break;
 end
 end
if (found==0)
     errordlg('Selected file does not match available extensions. Please select file from available extensions [ .jpg, .jpeg, .bmp, .png] ','Image Format Error');
end
% Disply image in current axes.

 set(handles.g3,'Visible','on');
set(handles.g4,'Visible','on');

% RGB component graph
r=handles.i(:,:,1);
g=handles.i(:,:,2);
b=handles.i(:,:,3);
x=size(r); x=(1:x(1,2));
r=r(1,:); g=g(1,:); b=b(1,:);
axes(handles.g3); plot(x,r,'r');
hold on
plot(x,g,'g'); plot(x,b,'b'); hold off;

updateg4(handles)

% --- Executes on button press in save.
function save_Callback(hObject, eventdata, handles)
% hObject    handle to save (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
[file path]= uiputfile('*.jpg','Save Image as');
save=[path file]; imwrite(handles.img,save,'jpg');

function dim_Callback(hObject, eventdata, handles)
% hObject    handle to dim (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of dim as text
%        str2double(get(hObject,'String')) returns contents of dim as a double

% --- Executes during object creation, after setting all properties.
function dim_CreateFcn(hObject, eventdata, handles)
% hObject    handle to dim (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function path_Callback(hObject, eventdata, handles)
% hObject    handle to path (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of path as text
%        str2double(get(hObject,'String')) returns contents of path as a double

% --- Executes during object creation, after setting all properties.
function path_CreateFcn(hObject, eventdata, handles)
% hObject    handle to path (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% --- Executes on slider movement.
function slider1_Callback(hObject, eventdata, handles)
% hObject    handle to slider1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
x=get(hObject,'Value');
r=handles.img(:,:,1);
g=handles.img(:,:,2); b=handles.img(:,:,3);
r1=r+x; rcon=cat(3,r1,g,b);
axes(handles.g2); cla; imshow(rcon)
set(handles.rv,'String',num2str(x));
handles.img=rcon;
r=handles.img(:,:,1);
g=handles.img(:,:,2);
b=handles.img(:,:,3);
x=size(r); x=(1:x(1,2));
r=r(1,:); g=g(1,:); b=b(1,:);
axes(handles.g4); plot(x,r,'r');
hold on
plot(x,g,'g'); plot(x,b,'b'); hold off;

% Hints: get(hObject,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider

% --- Executes during object creation, after setting all properties.
function slider1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to slider1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end

function rv_Callback(hObject, eventdata, handles)
% hObject    handle to rv (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of rv as text
%        str2double(get(hObject,'String')) returns contents of rv as a double

% --- Executes during object creation, after setting all properties.
function rv_CreateFcn(hObject, eventdata, handles)
% hObject    handle to rv (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

% --- Executes on slider movement.
function slider2_Callback(hObject, eventdata, handles)
% hObject    handle to slider2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

x=get(hObject,'Value');
r=handles.img(:,:,1);
g=handles.img(:,:,2); b=handles.img(:,:,3);
g1=g+x; gcon=cat(3,r,g1,b);
axes(handles.g2); cla; imshow(gcon)
set(handles.gv,'String',num2str(x));
handles.img=gcon;

updateg4(handles)
% Hints: get(hObject,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider

% --- Executes during object creation, after setting all properties.
function slider2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to slider2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end

function gv_Callback(hObject, eventdata, handles)
% hObject    handle to gv (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of gv as text
%        str2double(get(hObject,'String')) returns contents of gv as a double

% --- Executes during object creation, after setting all properties.
function gv_CreateFcn(hObject, eventdata, handles)
% hObject    handle to gv (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

% --- Executes on slider movement.
function slider3_Callback(hObject, eventdata, handles)
% hObject    handle to slider3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
x=get(hObject,'Value');
r=handles.img(:,:,1);
g=handles.img(:,:,2); b=handles.img(:,:,3);
b1=b+x; bcon=cat(3,r,g,b1);
axes(handles.g2); cla; imshow(bcon)
set(handles.bv,'String',num2str(x));
handles.img=bcon;
updateg4(handles)
% Hints: get(hObject,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider

% --- Executes during object creation, after setting all properties.
function slider3_CreateFcn(hObject, eventdata, handles)
% hObject    handle to slider3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end

function bv_Callback(hObject, eventdata, handles)
% hObject    handle to bv (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of bv as text
%        str2double(get(hObject,'String')) returns contents of bv as a double

% --- Executes during object creation, after setting all properties.
function bv_CreateFcn(hObject, eventdata, handles)
% hObject    handle to bv (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

% --- Executes on slider movement.
function slider4_Callback(hObject, eventdata, handles)
% hObject    handle to slider4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
x=get(hObject,'Value');
img=handles.img;
img=img.*x;
axes(handles.g2); cla; imshow(img)
set(handles.cv,'String',num2str(x));
handles.img=img;
updateg4(handles)
% Hints: get(hObject,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider

% --- Executes during object creation, after setting all properties.
function slider4_CreateFcn(hObject, eventdata, handles)
% hObject    handle to slider4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end

function cv_Callback(hObject, eventdata, handles)
% hObject    handle to cv (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of cv as text
%        str2double(get(hObject,'String')) returns contents of cv as a double

% --- Executes during object creation, after setting all properties.
function cv_CreateFcn(hObject, eventdata, handles)
% hObject    handle to cv (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

% --- Executes on slider movement.
function slider5_Callback(hObject, eventdata, handles)
% hObject    handle to slider5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
x=get(hObject,'Value');
img=handles.img;
img=img+x;
axes(handles.g2); cla; imshow(img)
set(handles.bbv,'String',num2str(x));
handles.img=img;
updateg4(handles)
% Hints: get(hObject,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider

% --- Executes during object creation, after setting all properties.
function slider5_CreateFcn(hObject, eventdata, handles)
% hObject    handle to slider5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end

function bbv_Callback(hObject, eventdata, handles)
% hObject    handle to bbv (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of bbv as text
%        str2double(get(hObject,'String')) returns contents of bbv as a double

% --- Executes during object creation, after setting all properties.
function bbv_CreateFcn(hObject, eventdata, handles)
% hObject    handle to bbv (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

% --- Executes on button press in reset.
function reset_Callback(hObject, eventdata, handles)
% hObject    handle to reset (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
handles.img=handles.i;
axes(handles.g2); cla; imshow(handles.img);
updateg4(handles);
s=num2str(size(handles.img)); set(handles.dim2,'String',s);
guidata(hObject,handles);

% --- Executes on button press in set1.
function set1_Callback(hObject, eventdata, handles)
% hObject    handle to set1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
axes(handles.g2); img=getimage;
handles.img=img; imshow(handles.img);
updateg4(handles);
guidata(hObject,handles);

% --- Executes on button press in set2.
function set2_Callback(hObject, eventdata, handles)
% hObject    handle to set2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
axes(handles.g2); img=getimage;
handles.img=img; imshow(handles.img);
updateg4(handles);
guidata(hObject,handles);

% --- Executes on button press in set3.
function set3_Callback(hObject, eventdata, handles)
% hObject    handle to set3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
axes(handles.g2); img=getimage;
handles.img=img; imshow(handles.img);
updateg4(handles);
guidata(hObject,handles);

% --- Executes on button press in set4.
function set4_Callback(hObject, eventdata, handles)
% hObject    handle to set4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
axes(handles.g2); img=getimage;
handles.img=img; imshow(handles.img);
updateg4(handles);
guidata(hObject,handles);

% --- Executes on button press in set5.
function set5_Callback(hObject, eventdata, handles)
% hObject    handle to set5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
axes(handles.g2); img=getimage;
handles.img=img; imshow(handles.img);
updateg4(handles);
guidata(hObject,handles);

function e1_Callback(hObject, eventdata, handles)
% hObject    handle to e1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of e1 as text
%        str2double(get(hObject,'String')) returns contents of e1 as a double

% --- Executes during object creation, after setting all properties.
function e1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to e1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function e2_Callback(hObject, eventdata, handles)
% hObject    handle to e2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of e2 as text
%        str2double(get(hObject,'String')) returns contents of e2 as a double

% --- Executes during object creation, after setting all properties.
function e2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to e2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

% --- Executes on button press in resize.
function resize_Callback(hObject, eventdata, handles)
% hObject    handle to resize (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
h=str2num(get(handles.e1,'String'));
w=str2num(get(handles.e2,'String'));
handles.img=imresize(handles.img, [h w]);
axes(handles.g2); cla; imshow(handles.img);
updateg4(handles);
s=num2str(size(handles.img)); set(handles.dim2,'String',s);
guidata(hObject,handles);

% --- Executes on selection change in chres.
function chres_Callback(hObject, eventdata, handles)
% hObject    handle to chres (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
val=get(hObject,'Value');
switch val
    case 1
        warndlg('Please select a resolution value');
    case 2   %256x256
            handles.res=handles.img;
            axes(handles.g2); cla;
            handles.res=imresize(imresize(handles.res,.5),1);
            imshow(handles.res);
            guidata(hObject, handles);
            handles.img=handles.res;
            updateg4(handles);

    case 3  % 128X128
            handles.res=handles.img;
            axes(handles.g2); cla;
            handles.res=imresize(imresize(handles.res,1/2),2);
            imshow(handles.res);
            guidata(hObject, handles);
            handles.img=handles.res; updateg4(handles);

    case 4 % 64x64
            handles.res=handles.img;
            axes(handles.g2); cla;
            handles.res=imresize(imresize(handles.res,1/4),4);
            imshow(handles.res);
            guidata(hObject, handles);
           handles.img=handles.res;  updateg4(handles);

    case 5  % 32x32
           handles.res=handles.img;
            axes(handles.g2); cla;
            handles.res=imresize(imresize(handles.res,1/8),8);
            imshow(handles.res);
            guidata(hObject, handles);
           handles.img=handles.res;  updateg4(handles);

        case 6  % 16x16
            handles.res=handles.img;
            axes(handles.g2); cla;
            handles.res=imresize(imresize(handles.res,1/16),16);
            imshow(handles.res);
            guidata(hObject, handles);
           handles.img=handles.res;  updateg4(handles);

        case 7  % 8x8
            handles.res=handles.img;
            axes(handles.g2); cla;
            handles.res=imresize(imresize(handles.res,1/32),32);
            imshow(handles.res);
            guidata(hObject, handles);
            handles.img=handles.res; updateg4(handles);
end

        % Hints: contents = cellstr(get(hObject,'String')) returns chres contents as cell array
%        contents{get(hObject,'Value')} returns selected item from chres

% --- Executes during object creation, after setting all properties.
function chres_CreateFcn(hObject, eventdata, handles)
% hObject    handle to chres (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

% --- Executes on button press in sres.
function sres_Callback(hObject, eventdata, handles)
% hObject    handle to sres (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
handles.img=handles.res;
axes(handles.g2); cla; imshow(handles.img);
s=num2str(size(handles.img)); set(handles.dim2,'String',s);
guidata(hObject,handles);
updateg4(handles);

% --- Executes on slider movement.
function slider6_Callback(hObject, eventdata, handles)
% hObject    handle to slider6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
rrv=(get(hObject,'Value'));
handles.rot=handles.img;
handles.rot=imrotate(handles.rot,rrv);
axes(handles.g2); cla; imshow(handles.rot);
guidata(hObject,handles)
% Hints: get(hObject,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider

% --- Executes during object creation, after setting all properties.
function slider6_CreateFcn(hObject, eventdata, handles)
% hObject    handle to slider6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end

function rrv_Callback(hObject, eventdata, handles)
% hObject    handle to rrv (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of rrv as text
%        str2double(get(hObject,'String')) returns contents of rrv as a double

% --- Executes during object creation, after setting all properties.
function rrv_CreateFcn(hObject, eventdata, handles)
% hObject    handle to rrv (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

% --- Executes on button press in set6.
function set6_Callback(hObject, eventdata, handles)
% hObject    handle to set6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
handles.img=handles.rot;
axes(handles.g2); cla; imshow(handles.img);
updateg4(handles);
guidata(hObject,handles);

% --- Executes on button press in p1.
function p1_Callback(hObject, eventdata, handles)
% hObject    handle to p1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
h = waitbar(0,'Please wait...');
steps = 100;
for step = 1:steps
    % computations take place here
    waitbar(step / steps)
end
close(h)
imageinfo(handles.file);

% --- Executes on button press in p2.
function p2_Callback(hObject, eventdata, handles)
% hObject    handle to p2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
if (get(hObject,'Value')==get(hObject,'Max'))
axes(handles.g2); imdistline
elseif (get(hObject,'Value')==get(hObject,'Min'))
    axes(handles.g2); imshow(handles.img)
end
% Hint: get(hObject,'Value') returns toggle state of p2

% --- Executes on button press in p3.
function p3_Callback(hObject, eventdata, handles)
% hObject    handle to p3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
impixelinfo;
% Hint: get(hObject,'Value') returns toggle state of p3

% --- Executes on button press in p4.
function p4_Callback(hObject, eventdata, handles)
% hObject    handle to p4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
if (get(hObject,'Value')==get(hObject,'Max'))
axes(handles.g2); impixelregion
elseif (get(hObject,'Value')==get(hObject,'Min'))
    axes(handles.g2); imshow(handles.img)
end

% Hint: get(hObject,'Value') returns toggle state of p4

% --- Executes on button press in p5.
function p5_Callback(hObject, eventdata, handles)
% hObject    handle to p5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
imscrollpanel(handles.g2,handles.img);

% --- Executes on button press in p6.
function p6_Callback(hObject, eventdata, handles)
% hObject    handle to p6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
imoverview(handles.image)

% --- Executes on button press in p7.
function p7_Callback(hObject, eventdata, handles)
% hObject    handle to p7 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% --- Executes on selection change in selectcm.
function selectcm_Callback(hObject, eventdata, handles)
% hObject    handle to selectcm (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
handles.cm=handles.img;
val=get(hObject,'Value');
switch val
    case 1
        helpdlg('Please first select a color map','Color Map help');
    case 2
        handles.cm=rgb2ind(handles.cm,jet);
        handles.cm=ind2rgb(handles.cm,jet);
        axes(handles.g2); cla; imshow(handles.cm);
        guidata(hObject,handles);
        handles.img=handles.cm;
        updateg4(handles);
    case 3
        handles.cm=rgb2ind(handles.cm,HSV);
        handles.cm=ind2rgb(handles.cm,HSV);
        axes(handles.g2); cla; imshow(handles.cm);
        guidata(hObject,handles);
        handles.img=handles.cm;
        updateg4(handles);
    case 4
        handles.cm=rgb2ind(handles.cm,hot);
        handles.cm=ind2rgb(handles.cm,hot);
        axes(handles.g2); cla; imshow(handles.cm);
        guidata(hObject,handles);
        handles.img=handles.cm;
        updateg4(handles);
    case 5
        handles.cm=rgb2ind(handles.cm,cool);
        handles.cm=ind2rgb(handles.cm,cool);
        axes(handles.g2); cla; imshow(handles.cm);
        guidata(hObject,handles);
        handles.img=handles.cm;
        updateg4(handles);
    case 6
        handles.cm=rgb2ind(handles.cm,spring);
        handles.cm=ind2rgb(handles.cm,spring);
        axes(handles.g2); cla; imshow(handles.cm);
        guidata(hObject,handles);
        handles.img=handles.cm;
        updateg4(handles);
    case 7
        handles.cm=rgb2ind(handles.cm,summer);
        handles.cm=ind2rgb(handles.cm,summer);
        axes(handles.g2); cla; imshow(handles.cm);
        guidata(hObject,handles);
        handles.img=handles.cm;
       updateg4(handles);
    case 8
        handles.cm=rgb2ind(handles.cm,autumn);
        handles.cm=ind2rgb(handles.cm,autumn);
        axes(handles.g2); cla; imshow(handles.cm);
        guidata(hObject,handles);
        handles.img=handles.cm;
        updateg4(handles);
    case 9
        handles.cm=rgb2ind(handles.cm,winter);
        handles.cm=ind2rgb(handles.cm,winter);
        axes(handles.g2); cla; imshow(handles.cm);
        guidata(hObject,handles);
        handles.img=handles.cm;
        updateg4(handles);
    case 10
        handles.cm=rgb2ind(handles.cm,gray);
        handles.cm=ind2rgb(handles.cm,gray);
        axes(handles.g2); cla; imshow(handles.cm);
        guidata(hObject,handles);
        handles.img=handles.cm;
        updateg4(handles);
    case 11
        handles.cm=rgb2ind(handles.cm,bone);
        handles.cm=ind2rgb(handles.cm,bone);
        axes(handles.g2); cla; imshow(handles.cm);
        guidata(hObject,handles);
        handles.img=handles.cm;
        updateg4(handles);
    case 12
        handles.cm=rgb2ind(handles.cm,copper);
        handles.cm=ind2rgb(handles.cm,copper);
        axes(handles.g2); cla; imshow(handles.cm);
        guidata(hObject,handles);
        handles.img=handles.cm;
        updateg4(handles);
    case 13
        handles.cm=rgb2ind(handles.cm,pink);
        handles.cm=ind2rgb(handles.cm,pink);
        axes(handles.g2); cla; imshow(handles.cm);
        guidata(hObject,handles);
        handles.img=handles.cm;
        updateg4(handles);
    case 14
        handles.cm=rgb2ind(handles.cm,lines);
        handles.cm=ind2rgb(handles.cm,lines);
        axes(handles.g2); cla; imshow(handles.cm);
        guidata(hObject,handles);
        handles.img=handles.cm;
        updateg4(handles);
end
% Hints: contents = cellstr(get(hObject,'String')) returns selectcm contents as cell array
%        contents{get(hObject,'Value')} returns selected item from selectcm

% --- Executes during object creation, after setting all properties.
function selectcm_CreateFcn(hObject, eventdata, handles)
% hObject    handle to selectcm (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

% --- Executes on button press in setcm.
function setcm_Callback(hObject, eventdata, handles)
% hObject    handle to setcm (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
handles.img=handles.cm;
axes(handles.g2); cla; imshow(handles.img);
updateg4(handles);
guidata(hObject,handles);

% --- Executes on button press in invc.
function invc_Callback(hObject, eventdata, handles)
% hObject    handle to invc (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
x=handles.img;
r=x(:,:,1); r=256-r;
g=x(:,:,2); g=256-g;
b=x(:,:,3); b=256-b;
handles.img=cat(3,r,g,b);
axes(handles.g2); cla; imshow(handles.img);
updateg4(handles);
guidata(hObject,handles);
% --- Executes on button press in autoa.
function autoa_Callback(hObject, eventdata, handles)
% hObject    handle to autoa (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
    handles.img= imadjust(handles.img,[.2 .3 0; .6 .7 1],[]);
   axes(handles.g2); cla; imshow(handles.img);
   guidata(hObject,handles);
   updateg4(handles);

% --- Executes on button press in rgbo.
function rgbo_Callback(hObject, eventdata, handles)
% hObject    handle to rgbo (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
r=handles.i(:,:,1);
g=handles.i(:,:,2);
b=handles.i(:,:,3);
figure,subplot(1,3,1)
imshow(r); title('RED Plane');
subplot(1,3,2)
imshow(g); title('Green Plane');
subplot(1,3,3)
imshow(b); title('Blue Plane');
% --- Executes on button press in rgbm.
function rgbm_Callback(hObject, eventdata, handles)
% hObject    handle to rgbm (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
r=handles.img(:,:,1);
g=handles.img(:,:,2);
b=handles.img(:,:,3);
figure,subplot(1,3,1)
imshow(r); title('RED Plane');
subplot(1,3,2)
imshow(g); title('Green Plane');
subplot(1,3,3)
imshow(b); title('Blue Plane');

% --- Executes on button press in exit.
function exit_Callback(hObject, eventdata, handles)
% hObject    handle to exit (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
close all;

% --- Executes on button press in autocon.
function autocon_Callback(hObject, eventdata, handles)
% hObject    handle to autocon (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
r=handles.img(:,:,1);  r=histeq(r);
g=handles.img(:,:,2);  g=histeq(g);
b=handles.img(:,:,3);  b=histeq(b);
handles.img=cat(3,r,g,b);
axes(handles.g2); cla; imshow(handles.img);
guidata(hObject,handles);
updateg4(handles);

% --- Executes on button press in n1.
function n1_Callback(hObject, eventdata, handles)
% hObject    handle to n1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA
    handles.img = imnoise(handles.img,'gaussian');
    axes(handles.g2); cla; imshow(handles.img);
guidata(hObject,handles);
updateg4(handles);

% --- Executes on button press in n3.
function n3_Callback(hObject, eventdata, handles)
% hObject    handle to n3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
h = waitbar(0,'Please wait...');
steps = 200;
for step = 1:steps
    % computations take place here
    waitbar(step / steps)
end
close(h)
handles.img = imnoise(handles.img,'poisson');
    axes(handles.g2); cla; imshow(handles.img);
guidata(hObject,handles);
updateg4(handles);

% --- Executes on button press in n4.
function n4_Callback(hObject, eventdata, handles)
% hObject    handle to n4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
handles.img = imnoise(handles.img,'salt & pepper',0.02);
    axes(handles.g2); cla; imshow(handles.img);
guidata(hObject,handles);
updateg4(handles);

% --- Executes on button press in n5.
function n5_Callback(hObject, eventdata, handles)
% hObject    handle to n5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
handles.img = imnoise(handles.img,'speckle',0.04);
    axes(handles.g2); cla; imshow(handles.img);
guidata(hObject,handles);
updateg4(handles);

% --- Executes on button press in f1.
function f1_Callback(hObject, eventdata, handles)
% hObject    handle to f1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
h=fspecial('average');
handles.img=imfilter(handles.img,h,'replicate');
axes(handles.g2); cla; imshow(handles.img)
guidata(hObject,handles);
updateg4(handles);

% --- Executes on button press in crop.
function crop_Callback(hObject, eventdata, handles)
% hObject    handle to crop (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
imcrop(handles.g2);
handles.img=getimage(gca); close;
axes(handles.g2); cla; imshow(handles.img)
s=num2str(size(handles.img)); set(handles.dim2,'String',s);
guidata(hObject,handles);
updateg4(handles);

function dim2_Callback(hObject, eventdata, handles)
% hObject    handle to dim2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of dim2 as text
%        str2double(get(hObject,'String')) returns contents of dim2 as a double

% --- Executes during object creation, after setting all properties.
function dim2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to dim2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

% --- Executes on button press in info.
function info_Callback(hObject, eventdata, handles)
% hObject    handle to info (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
h = waitbar(0,'Please wait...');
steps = 100;
for step = 1:steps
    % computations take place here
    waitbar(step / steps)
end
close(h)
imageinfo(handles.g2);

% --- Executes on button press in dia.
function dia_Callback(hObject, eventdata, handles)
% hObject    handle to dia (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
handles.mori=handles.img;
str=strel(handles.strel,handles.value);
handles.mori=imdilate(handles.mori,str);
axes(handles.g2); cla; imshow(handles.mori)
guidata(hObject,handles);
handles.img=handles.mori;
updateg4(handles);

%imscrollpanel(handles.g2,handles.img);

% --- Executes on button press in f3.
function f3_Callback(hObject, eventdata, handles)
% hObject    handle to f3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
r=medfilt2(handles.img(:,:,1)); g=medfilt2(handles.img(:,:,2)); b=medfilt2(handles.img(:,:,3));
handles.img=cat(3,r,g,b);
axes(handles.g2); cla; imshow(handles.img);
guidata(hObject,handles);
updateg4(handles);

% --- Executes on button press in f2.
function f2_Callback(hObject, eventdata, handles)
% hObject    handle to f2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
hsize=[8 8]; sigma=1.7;
h=fspecial('gaussian',hsize,sigma);
handles.img=imfilter(handles.img,h,'replicate');
axes(handles.g2); cla; imshow(handles.img);
guidata(hObject,handles);
updateg4(handles);

% --- Executes on button press in f4.
function f4_Callback(hObject, eventdata, handles)
% hObject    handle to f4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
h=fspecial('unsharp');
handles.img=imfilter(handles.img,h,'replicate');
axes(handles.g2); cla; imshow(handles.img)
guidata(hObject,handles);
updateg4(handles);

% --- Executes on button press in ero.
function ero_Callback(hObject, eventdata, handles)
% hObject    handle to ero (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
handles.mori=handles.img;
str=strel(handles.strel,handles.value);
handles.mori=imerode(handles.mori,str);
axes(handles.g2); cla; imshow(handles.mori)
guidata(hObject,handles);
handles.img=handles.mori;
updateg4(handles);

% --- Executes on selection change in strel.
function strel_Callback(hObject, eventdata, handles)
% hObject    handle to strel (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
val=get(hObject,'Value');
switch val
        case 1
        helpdlg('Please first select Structring Element and value ','Morphological Operations');
        case 2
        handles.strel='diamond';
        case 3
        handles.strel='disk';
        case 4
        helpdlg('Value must be a nonnegative multiple of 3.','Octagon Structure Help');
        handles.strel='octagon';
end
guidata(hObject,handles);
% Hints: contents = cellstr(get(hObject,'String')) returns strel contents as cell array
%        contents{get(hObject,'Value')} returns selected item from strel

% --- Executes during object creation, after setting all properties.
function strel_CreateFcn(hObject, eventdata, handles)
% hObject    handle to strel (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function strelv_Callback(hObject, eventdata, handles)
% hObject    handle to strelv (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
handles.value=str2num(get(hObject,'String'));
guidata(hObject,handles);
% Hints: get(hObject,'String') returns contents of strelv as text
%        str2double(get(hObject,'String')) returns contents of strelv as a double

% --- Executes during object creation, after setting all properties.
function strelv_CreateFcn(hObject, eventdata, handles)
% hObject    handle to strelv (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

% --- Executes on button press in strels.
function strels_Callback(hObject, eventdata, handles)
% hObject    handle to strels (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
handles.img=handles.mori;
axes(handles.g2); cla; imshow(handles.img)
guidata(hObject,handles);
updateg4(handles);

% --- Executes on button press in dfh1.
function dfh1_Callback(hObject, eventdata, handles)
% hObject    handle to dfh1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
helpdlg('Click and draw a free hand on ORIGNAL image & then press ENTER. ');
axes(handles.g1); improfile; grid on;

% --- Executes on button press in dfh2.
function dfh2_Callback(hObject, eventdata, handles)
% hObject    handle to dfh2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
helpdlg('Click and draw a free hand on MODIFIED image & then press ENTER. ');
axes(handles.g2); improfile; grid on;

% --------------------------------------------------------------------
function ex_Callback(hObject, eventdata, handles)
% hObject    handle to ex (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
close;

author: Sable

repo: mcbench-benchmarks


text:
function Lms = kappabeta_ach(Ns, epsil, P, hack)
%
% Compute achievability (lower) bound for log M. This is just a glue between kappa() and betaq_up_v2()
%

if (nargin < 4) || isempty(hack)
	hack = 1;
end

taus = linspace(0,1,40).*epsil; taus = taus(3:end-2);

Lms = [];

for n = Ns;
	disp(sprintf('kappabeta_ach(): n = %d', n));
	temp_lbs = [];
	for tau = taus;
		temp_lb = log2(kappa_inf(tau, P)) - betaq_up_v2(1-epsil+tau, n, P);
		temp_lbs = [temp_lbs temp_lb];
	end;
	[bb ind] = max(temp_lbs);
	tau = taus(ind);
	if (hack)
		kap = log2(kappa_inf(tau, P));
	else
		kap = log2(kappa(tau, n, P));
	end
	clb = kap - betaq_up_v2(1 - epsil + tau, n, P);

	Lms = [Lms clb];

end

author: yp-mit

repo: spectre

save_path: github-repos/MATLAB/yp-mit-spectre


text:
function s = resampdet(p,m,n);
%RESAMPDET Deterministic resampling
%
%   Description
%   S = RESAMPDET(P) returns a new set of indices according to the
%   probabilities P. P is array of probabilities, which are not
%   necessarily normalized, though they must be non-negative, and
%   not all zero. The size of S is the size of P.
%
%   S = RESAMPDET(P,M,N) returns M by N matrix.
%
%   S = RESAMPDET(P,M) returns M by M matrix.
%
%   Default is to use no-sort resampling. For sorted resampling use
%    [PS,PI]=SORT(P);
%    S=PI(RESAMPDET(PS));
%   Sorted re-sampling is slower but has smaller variance. Note
%   that deterministic resampling is not unbiased. Stratified
%   resampling (RESAMPSTR) is unbiased, almost as fast as
%   deterministic resampling, and has only slightly larger
%   variance.
%
%   In deterministic resampling indices are sampled using
%   deterministic numbers u_j~(j-a)/n, for fixed a in [0,1) and
%   n is length of P. Compare this to simple random resampling
%   where u_j~U[0,n]. See, Kitagawa, G., Monte Carlo Filter and
%   Smoother for Non-Gaussian Nonlinear State Space Models,
%   Journal of Computational and Graphical Statistics, 5(1):1-25,
%   1996.
%
%   See also RESAMPSIM, RESAMPRES, RESAMPSTR

% Copyright (c) 2003-2004 Aki Vehtari

% This software is distributed under the GNU General Public
% License (version 3 or later); please refer to the file
% License.txt, included with the software, for details.

if nargin<2
    [m,n]=size(p);
elseif nargin==2
    n=m;
end
mn=m.*n;
pn=p./sum(p(:)).*mn;
fpn=floor(pn);
s=zeros(m,n);
k=0;
c=0.5;
for i=1:numel(p)
  if pn(i)>=1
    a=fpn(i);
    pn(i)=pn(i)-a;
    s(k+[1:a])=i;
    k=k+a;
  end
  c=c+pn(i);
  if c>=1
    k=k+1;
    s(k)=i;
    c=c-1;
  end
end

author: fieldtrip

repo: fieldtrip

save_path: github-repos/MATLAB/fieldtrip-fieldtrip


text:
% MP_SOLVE_STOKES_DIV_CONFORMING: Solve a Stokes flow problem on a multipatch domain with
% divergence-conforming spaces, using an interior penalty method between patches.
%
% The function solves the Stokes problem
%
%   -div(mu(x) grad(vel)) + grad(press) = f    in Omega
%                              div(vel) = 0    in Omega
%                                   vel = h    on Gamma_D
%
% USAGE:
%
%  [geometry, msh, space_v, vel, space_p, press] = ...
%                        mp_solve_stokes_div_conforming (problem_data, method_data)
%
% INPUT:
%
%  problem_data: a structure with data of the problem. It contains the fields:
%    - geo_name:     name of the file containing the geometry
%    - drchlt_sides: sides with Dirichlet boundary condition
%    - f:            force term
%    - h:            function for Dirichlet boundary condition
%    - viscosity:    viscosity coefficient (mu in the equation)
%
%  method_data : a structure with discretization data. Its fields are:
%    - degree:       degree of the spline functions for pressure
%    - regularity:   continuity of the spline functions for pressure
%    - nsub:       number of subelements with respect to the geometry mesh
%                   for the pressure space (nsub=1 leaves the mesh unchanged)
%    - nquad:        number of points for Gaussian quadrature rule
%    - element_name: one of {RT,NDL}, specify how to build the velocity
%                    space from the data for the pressure space
%                     +RT  is the generalized Raviart-Thomas element
%                     +NDL is the generalized Nedelec element of the second family
% OUTPUT:
%
%  geometry: array of geometry structures (see geo_load)
%  msh:      multipatch mesh, consisting of several Cartesian meshes (see msh_multipatch)
%  space_v:  multipatch space, formed by several tensor product spaces plus the connectivity (see sp_multipatch).
%              Only the normal component is continuous at the interfaces.
%  vel:      the computed degrees of freedom for the velocity
%  space_p:  multipatch space for the pressure (see sp_multipatch). The functions are discountinuous at the interfaces.
%  press:    the computed degrees of freedom for the pressure
%
%  See also EX_STOKES_BIFURCATION_2D_RT_MP for an example
%
% Copyright (C) 2009, 2010 Carlo de Falco
% Copyright (C) 2010, 2011, 2015, 2020 Rafael Vazquez
%
%    This program is free software: you can redistribute it and/or modify
%    it under the terms of the GNU General Public License as published by
%    the Free Software Foundation, either version 3 of the License, or
%    (at your option) any later version.

%    This program is distributed in the hope that it will be useful,
%    but WITHOUT ANY WARRANTY; without even the implied warranty of
%    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%    GNU General Public License for more details.
%
%    You should have received a copy of the GNU General Public License
%    along with this program.  If not, see <http://www.gnu.org/licenses/>.

function [geometry, msh, space_v, vel, space_p, press] = ...
              mp_solve_stokes_div_conforming (problem_data, method_data)

% Extract the fields from the data structures into local variables
data_names = fieldnames (problem_data);
for iopt  = 1:numel (data_names)
  eval ([data_names{iopt} '= problem_data.(data_names{iopt});']);
end
data_names = fieldnames (method_data);
for iopt  = 1:numel (data_names)
  eval ([data_names{iopt} '= method_data.(data_names{iopt});']);
end

if (strcmpi ('element_name', 'TH') || strcmpi ('element_name', 'SG'))
  error ('For TH and SG spaces, use mp_solve_stokes');
end

% Construct geometry structure, and information for interfaces and boundaries
[geometry, boundaries, interfaces, ~, boundary_interfaces] = mp_geo_load (geo_name);
npatch = numel (geometry);

msh = cell (1, npatch);
spv = cell (1, npatch);
spp = cell (1, npatch);
for iptc = 1:npatch
% Construct msh structure using the finest mesh
  msh_breaks = msh_set_breaks (element_name, ...
                                       geometry(iptc).nurbs.knots, nsub);
  rule      = msh_gauss_nodes (nquad);
  [qn, qw]  = msh_set_quad_nodes (msh_breaks, rule);
  msh{iptc} = msh_cartesian (msh_breaks, qn, qw, geometry(iptc));

% Construct space structure
  [spv{iptc}, spp{iptc}] = sp_bspline_fluid (element_name, ...
               geometry(iptc).nurbs.knots, nsub, degree, regularity, msh{iptc});
end

msh = msh_multipatch (msh, boundaries);
space_v = sp_multipatch (spv, msh, interfaces, boundary_interfaces);
space_p = sp_multipatch (spp, msh, interfaces, boundary_interfaces);
clear spv spp

% Compute and assemble the matrices
if (msh.rdim == 2)
  fun_one = @(x, y) ones (size(x));
elseif (msh.rdim == 3)
  fun_one = @(x, y, z) ones (size(x));
end

A = op_gradu_gradv_mp (space_v, space_v, msh, viscosity);
B = op_div_v_q_mp (space_v, space_p, msh);
E = (op_f_v_mp (space_p, msh, fun_one)).';
F = op_f_v_mp (space_v, msh, f);

vel   = zeros (space_v.ndof, 1);
press = zeros (space_p.ndof, 1);

% Apply DG techniques on the interfaces
A = A + mp_dg_penalty (space_v, msh, interfaces, viscosity, Cpen);

% Apply Neumann boundary conditions
rhs_nmnn = zeros(space_v.ndof,1);
Nbnd = cumsum ([0, boundaries.nsides]);
for iref = nmnn_sides
  iref_patch_list = Nbnd(iref)+1:Nbnd(iref+1);
  gref = @(varargin) g(varargin{:},iref);

  for bnd_side = 1:msh.boundaries(iref).nsides
    iptc = msh.boundaries(iref).patches(bnd_side);
    iside = msh.boundaries(iref).faces(bnd_side);

    msh_side = msh_eval_boundary_side (msh.msh_patch{iptc}, iside);
    msh_side_from_interior = msh_boundary_side_from_interior (msh.msh_patch{iptc}, iside);

    sp_bnd = space_v.sp_patch{iptc}.constructor (msh_side_from_interior);
    sp_bnd = sp_precompute (sp_bnd, msh_side_from_interior, 'value', true);
%     sp_bnd.dofs = 1:sp_bnd.ndof;

    x = cell (msh_side.rdim, 1);
    for idim = 1:msh_side.rdim
      x{idim} = reshape (msh_side.geo_map(idim,:,:), msh_side.nqn, msh_side.nel);
    end
    gval = reshape (gref(x{:}), msh.rdim, msh_side.nqn, msh_side.nel);
    rhs_nmnn(space_v.gnum{iptc}) = rhs_nmnn(space_v.gnum{iptc}) + ...
      op_f_v (sp_bnd, msh_side, gval);
  end
end

% Apply Dirichlet boundary conditions
[N_mat, N_rhs] = sp_weak_drchlt_bc_stokes (space_v, msh, drchlt_sides, h, viscosity, Cpen);
A = A - N_mat; F = F + N_rhs;
[vel_drchlt, drchlt_dofs] = sp_drchlt_l2_proj_udotn (space_v, msh, drchlt_sides, h);
vel(drchlt_dofs) = vel_drchlt;

int_dofs = setdiff (1:space_v.ndof, drchlt_dofs);
nintdofs = numel (int_dofs);
rhs_dir  = -A(int_dofs, drchlt_dofs)*vel(drchlt_dofs);

% Solve the linear system
if (isempty (nmnn_sides))
  mat = [A(int_dofs, int_dofs), -B(:,int_dofs).', sparse(nintdofs, 1);
         -B(:,int_dofs),        sparse(space_p.ndof, space_p.ndof), E.';
         sparse(1, nintdofs),   E, 0];
  rhs = [F(int_dofs) + rhs_dir;
         B(:, drchlt_dofs)*vel(drchlt_dofs);
         0];
  sol = mat \ rhs;
  vel(int_dofs) = sol(1:nintdofs);
  press = sol(1+nintdofs:end-1);
else
% With natural boundary condition, the constraint on the pressure is not needed.
  mat = [ A(int_dofs, int_dofs), -B(:,int_dofs).';
         -B(:,int_dofs),         sparse(size (B,1), size (B,1))];
  rhs = [F(int_dofs) + rhs_dir + rhs_nmnn(int_dofs);
         B(:, drchlt_dofs)*vel(drchlt_dofs)];
  sol = mat \ rhs;
  vel(int_dofs) = sol(1:nintdofs);
  press = sol(1+nintdofs:end);
end

end

author: rafavzqz

repo: geopdes

save_path: github-repos/MATLAB/rafavzqz-geopdes


text:
% DEMSWISSROLL1 Model the face swiss roll with a 2-D GPLVM.

% FGPLVM

% Fix seeds
randn('seed', 1e6);
rand('seed', 1e6);

dataSetName = 'swissRollFull';
experimentNo = 2;

% load data
[Y, lbls] = lvmLoadData(dataSetName);

% Set up model
options = fgplvmOptions('dtcvar');
%options.optimiser = 'conjgrad';

latentDim = 2;
d = size(Y, 2);
options.initX = 'isomap';
model = fgplvmCreate(latentDim, d, Y, options);

% Optimise the model.
iters = 1000;
display = 1;

model = fgplvmOptimise(model, display, iters);

% Save the results.
modelWriteResult(model, dataSetName, experimentNo);

if exist('printDiagram') & printDiagram
  lvmPrintPlot(model, lbls, dataSetName, experimentNo);
end

% Display results
fgplvmScatterPlotColor(model, model.y(:, 3));

author: SheffieldML

repo: GPmat

save_path: github-repos/MATLAB/SheffieldML-GPmat


text:
function cycle_floyd_test02 ( )

%*****************************************************************************80
%
%% CYCLE_FLOYD_TEST02 tests CYCLE_FLOYD for F2.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    17 June 2012
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'CYCLE_FLOYD_TEST02\n' );
  fprintf ( 1, '  Test CYCLE_FLOYD for F2().\n' );
  fprintf ( 1, '  f2(i) = mod ( 22 * i + 1, 72 ).\n' );

  x0 = 0;
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Starting argument X0 = %d\n', x0 );

  [ lam, mu ] = cycle_floyd ( @f2, x0 );

  fprintf ( 1, '\n' );
  fprintf ( 1, '  Reported cycle length is %d\n', lam );
  fprintf ( 1, '  Expected value is 9\n' );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Reported distance to first cycle element is %d\n', mu );
  fprintf ( 1, '  Expected value is 3\n' );

  return
end


text:
function scatterplot(iter,ubest,fval,action,gpstruct,optimState,options)
%SCATTERPLOT Scatter plot of optimization iteration

if size(gpstruct.x, 1) == 0; return; end

figure(100);

nvars = size(gpstruct.x,2);
MeshSize = optimState.meshsize;

if options.Debug
    display(['GP hyper-parameters at iteration ' num2str(iter) ':']);
    gpstruct.hyp.mean
    (gpstruct.hyp.cov')
    (gpstruct.hyp.lik)
end

nrows = 2;
ncols = ceil((ceil(nvars/2) + 1)/2);

for iDim = 1:ceil(nvars/2)
    subplot(nrows,ncols,iDim);
    d1 = iDim*2 - 1;
    d2 = min(nvars,iDim*2);

    index = 1:optimState.Xmax;
    hold off;

    % Plot mesh size box
    s = MeshSize*ones(1,nvars);
    sstar = ubest;
    plot([sstar(d1) + s(d1),sstar(d1) + s(d1),sstar(d1) - s(d1),sstar(d1) - s(d1),sstar(d1) + s(d1)], ...
        [sstar(d2) - s(d2),sstar(d2) + s(d2),sstar(d2) + s(d2),sstar(d2) - s(d2),sstar(d2) - s(d2)], ...
        '-','LineWidth',1,'Color',[0.25 0.5 0]); hold on;

    % Plot all points
    idx = isfinite(optimState.Y(index(1:end-1)));
    plot(optimState.U(idx,d1),optimState.U(idx,d2),'.','MarkerSize',5,'MarkerFaceColor',[0 0 0]);
    idx = ~isfinite(optimState.Y(index(1:end-1)));
    plot(optimState.U(idx,d1),optimState.U(idx,d2),'*','MarkerSize',5,'MarkerFaceColor',[0 0 0]);

    % Plot training set
    if ~isfield(gpstruct,'erry') || isempty(gpstruct.erry); erry = false(size(gpstruct.y)); else erry = gpstruct.erry; end
    idx = ~erry;
    plot(gpstruct.x(idx,d1),gpstruct.x(idx,d2),'o','MarkerSize',5,'MarkerFaceColor',[0.5 0.5 0.5],'MarkerEdgeColor','none');
    idx = erry;
    plot(gpstruct.x(idx,d1),gpstruct.x(idx,d2),'*','MarkerSize',5,'MarkerFaceColor',[0.5 0.5 0.5],'MarkerEdgeColor',[0.5 0.5 0.5]);

    miny = min(optimState.Y(index));
    maxy = max(optimState.Y(index));
    deg = (optimState.Y(index) - miny)./(maxy - miny);
    %for iX = 1:optimState.Xmax
    %    col = bsxfun(@plus, deg*0.8, 0.1*[1 1 1]);
    %    plot(optimState.X(iX,d1),optimState.X(iX,d2),'o','MarkerFaceColor',col(iX,:)); hold on;
    %end

    % Plot true minimum
    if ~isempty(options.TrueMinX)
        plot(options.TrueMinX(d1),options.TrueMinX(d2),'o','MarkerFaceColor',[0.25 0 1], 'MarkerEdgeColor', 'none');
    end

    % Plot last evaluated point
    plot(optimState.U(index(end),d1),optimState.U(index(end),d2),'o','MarkerFaceColor',[1 0.4 0.4]);

    % Plot incumbent
    plot(sstar(d1),sstar(d2),'d','MarkerFaceColor',[0.25 1 0], 'MarkerEdgeColor', 'none');

    box off;
    set(gca,'TickDir','out');

    % Zoom level
    s = 4*MeshSize*ones(1,nvars);
    abox = [sstar(d1),sstar(d1),sstar(d2),sstar(d2)] + [-s(d1),s(d1),-s(d2),s(d2)];
    axis(abox);
end

subplot(nrows,ncols,nrows*ncols);
cla(gca);
box off;
axis off;
text(0.2,0.9,['Iteration: ' num2str(iter)]);
text(0.2,0.8,['f-count: ' num2str(optimState.funccount)]);
text(0.2,0.7,['f(x): ' num2str(fval,'%.6g')]);
text(0.2,0.6,['MeshScale: ' num2str(MeshSize,'%.6g')]);
text(0.2,0.5,['Method: ']);
text(0.2,0.4,['Action: ' action]);

set(gcf,'Color','w');
drawnow;

end

author: acerbilab

repo: bads

save_path: github-repos/MATLAB/acerbilab-bads