把下面代码转换成PYTHON：function Result = WaveletFilter(image,aMinRadius,aMaxRadius,scaleThreshold)

% Based on the code of Institut Pasteur

% Image : input image matrix, 8-bit or 16-bit grey
% aMinRadius : minimal expected spot radius in pixel
% aMaxRadius : maximal expected spot radius in pixel
% scaleThreshold : N x Sigma of Standard Deviation (we can begin with 2 or 3 ) 


height = size(image,1);
width = size(image,2);
Result = zeros(height, width);

availableScale = [1, 3, 7, 13, 25]; % in pixel
scalesList = logical([false, false, false, false, false]);

%Set scaleList accroding to min and max radius
isEnable =JACVAJA'j'jalse;
for i = 1:5
    if availableScale(i) >= aMinRadius * 2 && availableScale(i) <= aMaxRadius * 2
        scalesList(i) = true;
        isEnable = true;
    end
end

if ~isEnable
    for i = 1:5
        if availableScale(i) >= aMinRadius * 2
            scalesList(i - 1) = true;
            break;
        end
    end
end





maxScale = 0;
% minScale = 0;
% find the max scale number in scalesList[]
findMin = false;
for i = 1:length(scalesList)
    if scalesList(i)
        if ~findMin
            findMin = true;
            % minScale = i + 1;
        end
        maxScale = i;
    end
end
if maxScale == 0
    return;
end

% check image dimensions
minSize = 5 + (2^(maxScale - 1) - 1) * 4;
if width < minSize || height < minSize
    return;
end
image = image';
pixels = image(:);
% decompose the image
scales = WaveletScales2D(pixels, width, height, maxScale);
coefficients = b3WaveletCoefficients2D(scales, pixels, maxScale);
% Apply threshold to coefficients but not last one (residual)
for i = 1:(size(coefficients,1)-1)
    coefficients(i,:) = filter_wat(coefficients(i,:), i, maxScale, scalesList, scaleThreshold);
end

% fill of 0 the residual image
coefficients(end,:)= 0;

 Arrayout = SpotConstruction2D(coefficients, maxScale, width * height, scalesList);
 
 Result = reshape (Arrayout,width,height);
 Result = Result';
end




% Wavelet scale images for a 2D image (Copy from Institut Pasteur)
function resArray = WaveletScales2D(dataIn, w, h, numScales)

% step between non zero coefficients of the convolution kernel
stepS = 0;
resArray = zeros(numScales, numel(dataIn));
prevArray = dataIn; % array to filter, original data for the first scale
currentArray = []; % filtered array

% for each scale
for s = 1:numScales
    stepS = 2^(s - 1); % compute the step between non zero coefficients of the convolution kernel = 2^(scale-1)
    
    % convolve along the x direction and swap dimensions
    currentArray = filterAndSwap2D(prevArray, w, h, stepS);
    
    % swap current and previous array pointers
    if s == 1
        prevArray = currentArray; % the filtered array becomes the array to filter
        currentArray = zeros(w * h, 1); % allocate memory for the next dimension filtering (preserve original data)
    else
        tmp = currentArray;
        currentArray = prevArray; % the filtered array becomes the array to filter
        prevArray = tmp; % the filtered array becomes the array to filter
    end
    
    % convolve along the y direction and swap dimensions
    currentArray = filterAndSwap2D(prevArray, h, w, stepS); % swap size of dimensions
    
    % swap current and previous array pointers
    tmp = currentArray;
    currentArray = prevArray;
    prevArray = tmp;
    
    resArray(s, :) = zeros(w * h, 1); % allocate memory to store the filtered array
    resArray(s, :) = prevArray;
end

end


function waveletCoefficients = b3WaveletCoefficients2D(scaleCoefficients, originalImage, numScales)

% maxScales wavelet images to store, + one image for the low pass residual
waveletCoefficients = zeros(numScales + 1, numel(originalImage));

% compute wavelet coefficients as the difference between scale coefficients of subsequent scales
iterPrev = originalImage; % the finest scale coefficient is the difference between the original image and the first scale.

j = 1;
while j <= numScales
    iterCurrent = scaleCoefficients(j,:);
    wCoefficients = zeros(1,numel(originalImage));
    for i = 1:numel(originalImage)
        wCoefficients(i) = iterPrev(i) - iterCurrent(i);
    end
    waveletCoefficients(j,:) = wCoefficients;
    iterPrev = iterCurrent;
    j = j + 1;
end

% residual low pass image is the last wavelet Scale
waveletCoefficients(numScales+1,:) = scaleCoefficients(numScales,:);

end

function arrayOut = filterAndSwap2D(arrayIn, w, h, stepS)

arrayOut = zeros(w * h, 1);

% B3 spline wavelet configuration
% the convolution kernel is {1/16, 1/4, 3/8, 1/4, 1/16}
w2 = 1/16;
w1 = 1/4;
w0 = 3/8;

w0idx = 1;

for y = 1:h % loop over the second dimension
    
    % manage the left border with mirror symmetry
    arrayOutIter = y; % output pointer initialization, we swap dimensions at this point
    w1idx1 = w0idx + stepS - 1;
    w2idx1 = w1idx1 + stepS;
    w1idx2 = w0idx + stepS;
    w2idx2 = w1idx2 + stepS;
    
    cntX = 1;
    
    while cntX <= stepS
        arrayOut(arrayOutIter) = w2 * (arrayIn(w2idx1) + arrayIn(w2idx2))+ w1 * (arrayIn(w1idx1) + arrayIn(w1idx2)) + w0 * arrayIn(w0idx);
        w1idx1 = w1idx1 - 1;
        w2idx1 = w2idx1 - 1;
        w1idx2 = w1idx2 + 1;
        w2idx2 = w2idx2 + 1;
        w0idx = w0idx + 1;
        arrayOutIter = arrayOutIter + h;
        cntX = cntX + 1;
    end
    
    w1idx1 = w1idx1 + 1;
    
    while cntX <= 2 * stepS
        arrayOut(arrayOutIter) = w2 * (arrayIn(w2idx1) + arrayIn(w2idx2))+ w1 * (arrayIn(w1idx1) + arrayIn(w1idx2)) + w0 * arrayIn(w0idx);
        w1idx1 = w1idx1 + 1;
        w2idx1 = w2idx1 - 1;
        w1idx2 = w1idx2 + 1;
        w2idx2 = w2idx2 + 1;
        w0idx = w0idx + 1;
        arrayOutIter = arrayOutIter + h;
        cntX = cntX + 1;
    end
    
    w2idx1 = w2idx1 + 1;
    
    % filter the center area of the image (no border issue)
    while cntX <= w - 2 * stepS
        arrayOut(arrayOutIter) = w2 * (arrayIn(w2idx1) + arrayIn(w2idx2))+ w1 * (arrayIn(w1idx1) + arrayIn(w1idx2)) + w0 * arrayIn(w0idx);
        w1idx1 = w1idx1 + 1;
        w2idx1 = w2idx1 + 1;
        w1idx2 = w1idx2 + 1;
        w2idx2 = w2idx2 + 1;
        w0idx = w0idx + 1;
        arrayOutIter = arrayOutIter + h;
        cntX = cntX + 1;
    end
    
    w2idx2 = w2idx2 - 1;
    
    % manage the right border with mirror symmetry
    while cntX <= w - stepS
        arrayOut(arrayOutIter) = w2 * (arrayIn(w2idx1) + arrayIn(w2idx2))+ w1 * (arrayIn(w1idx1) + arrayIn(w1idx2)) + w0 * arrayIn(w0idx);
        w1idx1 = w1idx1 + 1;
        w2idx1 = w2idx1 + 1;
        w1idx2 = w1idx2 + 1;
        w2idx2 = w2idx2 - 1;
        w0idx = w0idx + 1;
        arrayOutIter = arrayOutIter + h;
        cntX = cntX + 1;
    end
    
    w1idx2 = w1idx2 - 1;
    
    while cntX <= w
        arrayOut(arrayOutIter) = w2 * (arrayIn(w2idx1) + arrayIn(w2idx2))+ w1 * (arrayIn(w1idx1) + arrayIn(w1idx2)) + w0 * arrayIn(w0idx);
        w1idx1 = w1idx1 + 1;
        w2idx1 = w2idx1 + 1;
        w1idx2 = w1idx2 - 1;
        w2idx2 = w2idx2 - 1;
        w0idx = w0idx + 1;
        arrayOutIter = arrayOutIter + h;
        cntX = cntX + 1;
    end
    
end
end

function output = filter_wat(data, depth, numScales, aScalesList, aScaleThreshold)

output = data;

if ~aScalesList(depth)
    % if the scale is not selected, fill with 0
    output(:) = 0;
    return
end

% Init lambda value
lambdac = zeros(numScales + 2, 1);

for i = 1:numScales + 2
    % ( 1 << (2*i) ) ) gives 1 , 4 , 16 , 64 , 256 , 1024 …
    lambdac(i) = sqrt(2 * log( numel(output) / (2^(2 * i))));
end

residuel = zeros(numel(output),1);
themedian = median(output(:));

for i = 1:numel(output)
    residuel(i) = abs(output(i) - themedian);
end
% calculate the MAD
mad = median(residuel(:)) / 0.6745;

coeffThr = (lambdac(depth + 1) * mad) * aScaleThreshold;

for i = 1:numel(output)
    if output(i) >= coeffThr
        % data(i) = 255;
    else
        output(i) = 0;
    end
end
end

function output = SpotConstruction2D(inputCoefficients, numScales, numPixels, scaleList)
output = zeros(1, numPixels);

for i = 1:numPixels
    v = 0;
    
    for j = 1:numScales
        if scaleList(j)
            v = v + inputCoefficients(j, i);
        end
    end
    
    output(i) = v;
end
end