function waveletImageAnalyzer(image)
% WAVELETIMAGEANALYZER Decompose and visualize images
%
%   WAVELETIMAGEANALYZER opens the Wavelet Image Analyzer app. After the
%   app initializes, import an image for analysis by clicking the Import
%   button.
%
%   WAVELETIMAGEANALYZER(IMG) opens the Wavelet Image Analyzer app,
%   imports, and plots the discrete wavelet transform (DWT) decomposition
%   of the image, IMG. IMG is a real-valued 2-D or 3-D matrix of data type
%   double, single, uint8, or uint16. If IMG is 3-D, IMG is assumed to be a
%   color image in the RGB color space and the third dimension of IMG must
%   be 3.
%
%   % Example:
%   %   Load an image. Display its decomposition coefficients by importing
%   %   the image from the workspace to the Wavelet Image Analyzer.
%
%   load xbox
%   waveletImageAnalyzer(xbox)
%
%   See also wavedec2, waverec2, detcoef2, appcoef2
%

%   Copyright 2022 The MathWorks, Inc.

    if nargin
        validateInput(image)
        waveletimageanalyzer.internal.ImageAnalyzerImpl(image, inputname(1));
    else
        waveletimageanalyzer.internal.ImageAnalyzerImpl();
    end
end

function validateInput(value)
    isValid = (isa(value, 'single') || isa(value, 'double') ...
        || isa(value, 'uint8')) && allfinite(value) && isreal(value);
    if isValid
        [m, n, p] = size(value);
        isValid = m > 1 && n > 1 && (p == 1 || p == 3);
    end

    if ~isValid
        error(string(getString(message("wavelet_imageanalyzer:waveletimageanalyzer:invalidInputErrorMessage"))))
    end
end
