把下面Matlab代码转换成Python:function arrayOut = filterAndSwap2D(arrayIn, w, h, stepS) arrayOut…
- User
把下面Matlab代码转换成Python: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; endend end
- Assistant
- User
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 =false; 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
- Assistant