Laplacian Pyramid producing weird results?











up vote
1
down vote

favorite












I'm trying to make a Laplacian Pyramid based on this MATLAB code:



% I is the image array, where its size is r x c x 3(<-RGB channels).
function pyr = laplacian_pyramid(I,nlev)

r = size(I,1);
c = size(I,2);

% recursively build pyramid
pyr = cell(nlev,1);
filter = [.0625, .25, .375, .25, .0625];
J = I;
for l = 1:nlev - 1
% apply low pass filter, and downsample
I = downsample(J,filter);
odd = 2*size(I) - size(J); % for each dimension, check if the upsampled version has to be odd
% in each level, store difference between image and upsampled low pass version
pyr{l} = J - upsample(I,odd,filter);
J = I; % continue with low pass image
end
pyr{nlev} = J; % the coarest level contains the residual low pass image


Where, downsample() looks like this:



function R = downsample(I, filter)

border_mode = 'symmetric';

% low pass, convolve with separable filter
R = imfilter(I,filter,border_mode); %horizontal
R = imfilter(R,filter',border_mode); %vertical

% decimate
r = size(I,1);
c = size(I,2);
R = R(1:2:r, 1:2:c, :);


And here is upsample():



function R = upsample(I,odd,filter)

% increase resolution
I = padarray(I,[1 1 0],'replicate'); % pad the image with a 1-pixel border
r = 2*size(I,1);
c = 2*size(I,2);
k = size(I,3);
R = zeros(r,c,k);
R(1:2:r, 1:2:c, :) = 4*I; % increase size 2 times; the padding is now 2 pixels wide

% interpolate, convolve with separable filter
R = imfilter(R,filter); %horizontal
R = imfilter(R,filter'); %vertical

% remove the border
R = R(3:r - 2 - odd(1), 3:c - 2 - odd(2), :);


This MATLAB code is working properly. Just focus on the downsample() function, since my OpenCV version of that function is why my problem happens.





Now here is my attempt on the OpenCV version of this MATLAB code:



private List<Mat> laplacianPyramid(Mat mat,int depth)
{
//mat.type() is CV_8UC3 (16).
List<Mat> pyramid = new ArrayList<Mat>();
//I make a clone so I don't ruin the original matrix.
Mat clone = mat.clone();
Mat J = clone;
for(int i=0;i<=depth-2;i++)
{
clone = image_reduce(J);
Mat temp = new Mat();
Point odd = new Point(clone.size().height*2 - J.height(), clone.size().width*2 - J.width());
Core.subtract(J, image_expand(clone, odd), temp);
pyramid.add(temp);
J = clone;
}
pyramid.add(J);
return pyramid;
}


Here is my OpenCV version of upsample():



private Mat image_expand(Mat image, Point odd){
//I make a clone so I don't ruin the original image.
Mat imageClone = image.clone();
copyMakeBorder(imageClone, imageClone, 1, 1, 1, 1, BORDER_REPLICATE);
Mat kernelX = getGaussianKernel();
Mat kernelY = new Mat();
Core.transpose(kernelX, kernelY);
Mat UIntVer = new Mat(imageClone.size(), CV_8UC3);
imageClone.convertTo(UIntVer, CV_8UC3);
Imgproc.resize(UIntVer, UIntVer, new Size(imageClone.width()*2, imageClone.height()*2), 0, 0, Imgproc.INTER_NEAREST);

//Now implement the zero padding between each columns and rows, just like the MATLAB version.
Mat mask = new Mat(2,2, CV_8UC1);
int array = new int[2][2];
array[0][0] = 255;
array[1][0] = 0;
array[0][1] = 0;
array[1][1] = 0;
for (int i=0; i<2; i++) {
for (int j = 0; j < 2; j++) {
mask.put(i, j, array[i][j]);
}
}
//mask becomes twice the size of image.
Mat biggerMask = new Mat();
Core.repeat(mask, imageClone.height(), imageClone.width(), biggerMask);
List<Mat> rgbUIntVer = new ArrayList<Mat>();
Core.split(UIntVer,rgbUIntVer);
Core.bitwise_and(rgbUIntVer.get(0), biggerMask, rgbUIntVer.get(0));
Core.bitwise_and(rgbUIntVer.get(1), biggerMask, rgbUIntVer.get(1));
Core.bitwise_and(rgbUIntVer.get(2), biggerMask, rgbUIntVer.get(2));
Core.merge(rgbUIntVer, UIntVer);

int r = imageClone.height()*2;
int c = imageClone.width()*2;
Mat result = new Mat(r, c, CV_32FC3);
UIntVer.convertTo(UIntVer, CV_32FC3);
Scalar four = new Scalar(4);
Core.multiply(UIntVer, four, UIntVer);
Imgproc.sepFilter2D(UIntVer,result,-1,kernelX,kernelY,new Point(-1,-1) ,0,BORDER_DEFAULT);
Rect roi = new Rect(2, 2, c-4-(int)odd.y, r-4-(int)odd.x);
result = new Mat(result, roi);
return result;
}




The problem with this OpenCV version code is that the result is just pure bluish. Laplacian Pyramids are supposed to save edge detection results, but an example result is like this. The image above is the original input, and the image below is the bottom floor of the resulting pyramid.



enter image description here



I checked that the input image is read correctly. Something is off with my code, but I can't find where. Any help would be highly appreciated!



I am suspecting that some processing functions are working only on the R channel, and not the GB channel.





I found out that what's wrong is image_expand(). It simply just outputs a red versioned image, which explains why the result image is bluish, since the result image is the difference between the original image and the output of image_expand(). So the problem is in image_expand().





Just in case, here is my getGaussianKernel() code:



private Mat getGaussianKernel(){
float kernel = new float[5];
kernel[0]= 0.0625f;
kernel[1]=0.25f;
kernel[2]=0.375f;
kernel[3]=0.25f;
kernel[4]=0.0625f;
Mat mat = new Mat(5,1,CV_32FC1);
mat.put(0,0,kernel);
return mat;
}









share|improve this question
























  • Without looking at your code, I am just assuming there is something worng with channels. Perhaps you only apply the code to a single channel at some point, or you dont consider BGR-RGB conversions, or some other thing related to that.
    – Ander Biguri
    Nov 9 at 16:18










  • You should probably run that function with some code added that displays intermediate images. Compare those to your expectation of what they should look like, to narrow down where within the function it goes wrong.
    – Cris Luengo
    Nov 10 at 6:18















up vote
1
down vote

favorite












I'm trying to make a Laplacian Pyramid based on this MATLAB code:



% I is the image array, where its size is r x c x 3(<-RGB channels).
function pyr = laplacian_pyramid(I,nlev)

r = size(I,1);
c = size(I,2);

% recursively build pyramid
pyr = cell(nlev,1);
filter = [.0625, .25, .375, .25, .0625];
J = I;
for l = 1:nlev - 1
% apply low pass filter, and downsample
I = downsample(J,filter);
odd = 2*size(I) - size(J); % for each dimension, check if the upsampled version has to be odd
% in each level, store difference between image and upsampled low pass version
pyr{l} = J - upsample(I,odd,filter);
J = I; % continue with low pass image
end
pyr{nlev} = J; % the coarest level contains the residual low pass image


Where, downsample() looks like this:



function R = downsample(I, filter)

border_mode = 'symmetric';

% low pass, convolve with separable filter
R = imfilter(I,filter,border_mode); %horizontal
R = imfilter(R,filter',border_mode); %vertical

% decimate
r = size(I,1);
c = size(I,2);
R = R(1:2:r, 1:2:c, :);


And here is upsample():



function R = upsample(I,odd,filter)

% increase resolution
I = padarray(I,[1 1 0],'replicate'); % pad the image with a 1-pixel border
r = 2*size(I,1);
c = 2*size(I,2);
k = size(I,3);
R = zeros(r,c,k);
R(1:2:r, 1:2:c, :) = 4*I; % increase size 2 times; the padding is now 2 pixels wide

% interpolate, convolve with separable filter
R = imfilter(R,filter); %horizontal
R = imfilter(R,filter'); %vertical

% remove the border
R = R(3:r - 2 - odd(1), 3:c - 2 - odd(2), :);


This MATLAB code is working properly. Just focus on the downsample() function, since my OpenCV version of that function is why my problem happens.





Now here is my attempt on the OpenCV version of this MATLAB code:



private List<Mat> laplacianPyramid(Mat mat,int depth)
{
//mat.type() is CV_8UC3 (16).
List<Mat> pyramid = new ArrayList<Mat>();
//I make a clone so I don't ruin the original matrix.
Mat clone = mat.clone();
Mat J = clone;
for(int i=0;i<=depth-2;i++)
{
clone = image_reduce(J);
Mat temp = new Mat();
Point odd = new Point(clone.size().height*2 - J.height(), clone.size().width*2 - J.width());
Core.subtract(J, image_expand(clone, odd), temp);
pyramid.add(temp);
J = clone;
}
pyramid.add(J);
return pyramid;
}


Here is my OpenCV version of upsample():



private Mat image_expand(Mat image, Point odd){
//I make a clone so I don't ruin the original image.
Mat imageClone = image.clone();
copyMakeBorder(imageClone, imageClone, 1, 1, 1, 1, BORDER_REPLICATE);
Mat kernelX = getGaussianKernel();
Mat kernelY = new Mat();
Core.transpose(kernelX, kernelY);
Mat UIntVer = new Mat(imageClone.size(), CV_8UC3);
imageClone.convertTo(UIntVer, CV_8UC3);
Imgproc.resize(UIntVer, UIntVer, new Size(imageClone.width()*2, imageClone.height()*2), 0, 0, Imgproc.INTER_NEAREST);

//Now implement the zero padding between each columns and rows, just like the MATLAB version.
Mat mask = new Mat(2,2, CV_8UC1);
int array = new int[2][2];
array[0][0] = 255;
array[1][0] = 0;
array[0][1] = 0;
array[1][1] = 0;
for (int i=0; i<2; i++) {
for (int j = 0; j < 2; j++) {
mask.put(i, j, array[i][j]);
}
}
//mask becomes twice the size of image.
Mat biggerMask = new Mat();
Core.repeat(mask, imageClone.height(), imageClone.width(), biggerMask);
List<Mat> rgbUIntVer = new ArrayList<Mat>();
Core.split(UIntVer,rgbUIntVer);
Core.bitwise_and(rgbUIntVer.get(0), biggerMask, rgbUIntVer.get(0));
Core.bitwise_and(rgbUIntVer.get(1), biggerMask, rgbUIntVer.get(1));
Core.bitwise_and(rgbUIntVer.get(2), biggerMask, rgbUIntVer.get(2));
Core.merge(rgbUIntVer, UIntVer);

int r = imageClone.height()*2;
int c = imageClone.width()*2;
Mat result = new Mat(r, c, CV_32FC3);
UIntVer.convertTo(UIntVer, CV_32FC3);
Scalar four = new Scalar(4);
Core.multiply(UIntVer, four, UIntVer);
Imgproc.sepFilter2D(UIntVer,result,-1,kernelX,kernelY,new Point(-1,-1) ,0,BORDER_DEFAULT);
Rect roi = new Rect(2, 2, c-4-(int)odd.y, r-4-(int)odd.x);
result = new Mat(result, roi);
return result;
}




The problem with this OpenCV version code is that the result is just pure bluish. Laplacian Pyramids are supposed to save edge detection results, but an example result is like this. The image above is the original input, and the image below is the bottom floor of the resulting pyramid.



enter image description here



I checked that the input image is read correctly. Something is off with my code, but I can't find where. Any help would be highly appreciated!



I am suspecting that some processing functions are working only on the R channel, and not the GB channel.





I found out that what's wrong is image_expand(). It simply just outputs a red versioned image, which explains why the result image is bluish, since the result image is the difference between the original image and the output of image_expand(). So the problem is in image_expand().





Just in case, here is my getGaussianKernel() code:



private Mat getGaussianKernel(){
float kernel = new float[5];
kernel[0]= 0.0625f;
kernel[1]=0.25f;
kernel[2]=0.375f;
kernel[3]=0.25f;
kernel[4]=0.0625f;
Mat mat = new Mat(5,1,CV_32FC1);
mat.put(0,0,kernel);
return mat;
}









share|improve this question
























  • Without looking at your code, I am just assuming there is something worng with channels. Perhaps you only apply the code to a single channel at some point, or you dont consider BGR-RGB conversions, or some other thing related to that.
    – Ander Biguri
    Nov 9 at 16:18










  • You should probably run that function with some code added that displays intermediate images. Compare those to your expectation of what they should look like, to narrow down where within the function it goes wrong.
    – Cris Luengo
    Nov 10 at 6:18













up vote
1
down vote

favorite









up vote
1
down vote

favorite











I'm trying to make a Laplacian Pyramid based on this MATLAB code:



% I is the image array, where its size is r x c x 3(<-RGB channels).
function pyr = laplacian_pyramid(I,nlev)

r = size(I,1);
c = size(I,2);

% recursively build pyramid
pyr = cell(nlev,1);
filter = [.0625, .25, .375, .25, .0625];
J = I;
for l = 1:nlev - 1
% apply low pass filter, and downsample
I = downsample(J,filter);
odd = 2*size(I) - size(J); % for each dimension, check if the upsampled version has to be odd
% in each level, store difference between image and upsampled low pass version
pyr{l} = J - upsample(I,odd,filter);
J = I; % continue with low pass image
end
pyr{nlev} = J; % the coarest level contains the residual low pass image


Where, downsample() looks like this:



function R = downsample(I, filter)

border_mode = 'symmetric';

% low pass, convolve with separable filter
R = imfilter(I,filter,border_mode); %horizontal
R = imfilter(R,filter',border_mode); %vertical

% decimate
r = size(I,1);
c = size(I,2);
R = R(1:2:r, 1:2:c, :);


And here is upsample():



function R = upsample(I,odd,filter)

% increase resolution
I = padarray(I,[1 1 0],'replicate'); % pad the image with a 1-pixel border
r = 2*size(I,1);
c = 2*size(I,2);
k = size(I,3);
R = zeros(r,c,k);
R(1:2:r, 1:2:c, :) = 4*I; % increase size 2 times; the padding is now 2 pixels wide

% interpolate, convolve with separable filter
R = imfilter(R,filter); %horizontal
R = imfilter(R,filter'); %vertical

% remove the border
R = R(3:r - 2 - odd(1), 3:c - 2 - odd(2), :);


This MATLAB code is working properly. Just focus on the downsample() function, since my OpenCV version of that function is why my problem happens.





Now here is my attempt on the OpenCV version of this MATLAB code:



private List<Mat> laplacianPyramid(Mat mat,int depth)
{
//mat.type() is CV_8UC3 (16).
List<Mat> pyramid = new ArrayList<Mat>();
//I make a clone so I don't ruin the original matrix.
Mat clone = mat.clone();
Mat J = clone;
for(int i=0;i<=depth-2;i++)
{
clone = image_reduce(J);
Mat temp = new Mat();
Point odd = new Point(clone.size().height*2 - J.height(), clone.size().width*2 - J.width());
Core.subtract(J, image_expand(clone, odd), temp);
pyramid.add(temp);
J = clone;
}
pyramid.add(J);
return pyramid;
}


Here is my OpenCV version of upsample():



private Mat image_expand(Mat image, Point odd){
//I make a clone so I don't ruin the original image.
Mat imageClone = image.clone();
copyMakeBorder(imageClone, imageClone, 1, 1, 1, 1, BORDER_REPLICATE);
Mat kernelX = getGaussianKernel();
Mat kernelY = new Mat();
Core.transpose(kernelX, kernelY);
Mat UIntVer = new Mat(imageClone.size(), CV_8UC3);
imageClone.convertTo(UIntVer, CV_8UC3);
Imgproc.resize(UIntVer, UIntVer, new Size(imageClone.width()*2, imageClone.height()*2), 0, 0, Imgproc.INTER_NEAREST);

//Now implement the zero padding between each columns and rows, just like the MATLAB version.
Mat mask = new Mat(2,2, CV_8UC1);
int array = new int[2][2];
array[0][0] = 255;
array[1][0] = 0;
array[0][1] = 0;
array[1][1] = 0;
for (int i=0; i<2; i++) {
for (int j = 0; j < 2; j++) {
mask.put(i, j, array[i][j]);
}
}
//mask becomes twice the size of image.
Mat biggerMask = new Mat();
Core.repeat(mask, imageClone.height(), imageClone.width(), biggerMask);
List<Mat> rgbUIntVer = new ArrayList<Mat>();
Core.split(UIntVer,rgbUIntVer);
Core.bitwise_and(rgbUIntVer.get(0), biggerMask, rgbUIntVer.get(0));
Core.bitwise_and(rgbUIntVer.get(1), biggerMask, rgbUIntVer.get(1));
Core.bitwise_and(rgbUIntVer.get(2), biggerMask, rgbUIntVer.get(2));
Core.merge(rgbUIntVer, UIntVer);

int r = imageClone.height()*2;
int c = imageClone.width()*2;
Mat result = new Mat(r, c, CV_32FC3);
UIntVer.convertTo(UIntVer, CV_32FC3);
Scalar four = new Scalar(4);
Core.multiply(UIntVer, four, UIntVer);
Imgproc.sepFilter2D(UIntVer,result,-1,kernelX,kernelY,new Point(-1,-1) ,0,BORDER_DEFAULT);
Rect roi = new Rect(2, 2, c-4-(int)odd.y, r-4-(int)odd.x);
result = new Mat(result, roi);
return result;
}




The problem with this OpenCV version code is that the result is just pure bluish. Laplacian Pyramids are supposed to save edge detection results, but an example result is like this. The image above is the original input, and the image below is the bottom floor of the resulting pyramid.



enter image description here



I checked that the input image is read correctly. Something is off with my code, but I can't find where. Any help would be highly appreciated!



I am suspecting that some processing functions are working only on the R channel, and not the GB channel.





I found out that what's wrong is image_expand(). It simply just outputs a red versioned image, which explains why the result image is bluish, since the result image is the difference between the original image and the output of image_expand(). So the problem is in image_expand().





Just in case, here is my getGaussianKernel() code:



private Mat getGaussianKernel(){
float kernel = new float[5];
kernel[0]= 0.0625f;
kernel[1]=0.25f;
kernel[2]=0.375f;
kernel[3]=0.25f;
kernel[4]=0.0625f;
Mat mat = new Mat(5,1,CV_32FC1);
mat.put(0,0,kernel);
return mat;
}









share|improve this question















I'm trying to make a Laplacian Pyramid based on this MATLAB code:



% I is the image array, where its size is r x c x 3(<-RGB channels).
function pyr = laplacian_pyramid(I,nlev)

r = size(I,1);
c = size(I,2);

% recursively build pyramid
pyr = cell(nlev,1);
filter = [.0625, .25, .375, .25, .0625];
J = I;
for l = 1:nlev - 1
% apply low pass filter, and downsample
I = downsample(J,filter);
odd = 2*size(I) - size(J); % for each dimension, check if the upsampled version has to be odd
% in each level, store difference between image and upsampled low pass version
pyr{l} = J - upsample(I,odd,filter);
J = I; % continue with low pass image
end
pyr{nlev} = J; % the coarest level contains the residual low pass image


Where, downsample() looks like this:



function R = downsample(I, filter)

border_mode = 'symmetric';

% low pass, convolve with separable filter
R = imfilter(I,filter,border_mode); %horizontal
R = imfilter(R,filter',border_mode); %vertical

% decimate
r = size(I,1);
c = size(I,2);
R = R(1:2:r, 1:2:c, :);


And here is upsample():



function R = upsample(I,odd,filter)

% increase resolution
I = padarray(I,[1 1 0],'replicate'); % pad the image with a 1-pixel border
r = 2*size(I,1);
c = 2*size(I,2);
k = size(I,3);
R = zeros(r,c,k);
R(1:2:r, 1:2:c, :) = 4*I; % increase size 2 times; the padding is now 2 pixels wide

% interpolate, convolve with separable filter
R = imfilter(R,filter); %horizontal
R = imfilter(R,filter'); %vertical

% remove the border
R = R(3:r - 2 - odd(1), 3:c - 2 - odd(2), :);


This MATLAB code is working properly. Just focus on the downsample() function, since my OpenCV version of that function is why my problem happens.





Now here is my attempt on the OpenCV version of this MATLAB code:



private List<Mat> laplacianPyramid(Mat mat,int depth)
{
//mat.type() is CV_8UC3 (16).
List<Mat> pyramid = new ArrayList<Mat>();
//I make a clone so I don't ruin the original matrix.
Mat clone = mat.clone();
Mat J = clone;
for(int i=0;i<=depth-2;i++)
{
clone = image_reduce(J);
Mat temp = new Mat();
Point odd = new Point(clone.size().height*2 - J.height(), clone.size().width*2 - J.width());
Core.subtract(J, image_expand(clone, odd), temp);
pyramid.add(temp);
J = clone;
}
pyramid.add(J);
return pyramid;
}


Here is my OpenCV version of upsample():



private Mat image_expand(Mat image, Point odd){
//I make a clone so I don't ruin the original image.
Mat imageClone = image.clone();
copyMakeBorder(imageClone, imageClone, 1, 1, 1, 1, BORDER_REPLICATE);
Mat kernelX = getGaussianKernel();
Mat kernelY = new Mat();
Core.transpose(kernelX, kernelY);
Mat UIntVer = new Mat(imageClone.size(), CV_8UC3);
imageClone.convertTo(UIntVer, CV_8UC3);
Imgproc.resize(UIntVer, UIntVer, new Size(imageClone.width()*2, imageClone.height()*2), 0, 0, Imgproc.INTER_NEAREST);

//Now implement the zero padding between each columns and rows, just like the MATLAB version.
Mat mask = new Mat(2,2, CV_8UC1);
int array = new int[2][2];
array[0][0] = 255;
array[1][0] = 0;
array[0][1] = 0;
array[1][1] = 0;
for (int i=0; i<2; i++) {
for (int j = 0; j < 2; j++) {
mask.put(i, j, array[i][j]);
}
}
//mask becomes twice the size of image.
Mat biggerMask = new Mat();
Core.repeat(mask, imageClone.height(), imageClone.width(), biggerMask);
List<Mat> rgbUIntVer = new ArrayList<Mat>();
Core.split(UIntVer,rgbUIntVer);
Core.bitwise_and(rgbUIntVer.get(0), biggerMask, rgbUIntVer.get(0));
Core.bitwise_and(rgbUIntVer.get(1), biggerMask, rgbUIntVer.get(1));
Core.bitwise_and(rgbUIntVer.get(2), biggerMask, rgbUIntVer.get(2));
Core.merge(rgbUIntVer, UIntVer);

int r = imageClone.height()*2;
int c = imageClone.width()*2;
Mat result = new Mat(r, c, CV_32FC3);
UIntVer.convertTo(UIntVer, CV_32FC3);
Scalar four = new Scalar(4);
Core.multiply(UIntVer, four, UIntVer);
Imgproc.sepFilter2D(UIntVer,result,-1,kernelX,kernelY,new Point(-1,-1) ,0,BORDER_DEFAULT);
Rect roi = new Rect(2, 2, c-4-(int)odd.y, r-4-(int)odd.x);
result = new Mat(result, roi);
return result;
}




The problem with this OpenCV version code is that the result is just pure bluish. Laplacian Pyramids are supposed to save edge detection results, but an example result is like this. The image above is the original input, and the image below is the bottom floor of the resulting pyramid.



enter image description here



I checked that the input image is read correctly. Something is off with my code, but I can't find where. Any help would be highly appreciated!



I am suspecting that some processing functions are working only on the R channel, and not the GB channel.





I found out that what's wrong is image_expand(). It simply just outputs a red versioned image, which explains why the result image is bluish, since the result image is the difference between the original image and the output of image_expand(). So the problem is in image_expand().





Just in case, here is my getGaussianKernel() code:



private Mat getGaussianKernel(){
float kernel = new float[5];
kernel[0]= 0.0625f;
kernel[1]=0.25f;
kernel[2]=0.375f;
kernel[3]=0.25f;
kernel[4]=0.0625f;
Mat mat = new Mat(5,1,CV_32FC1);
mat.put(0,0,kernel);
return mat;
}






java android matlab opencv image-processing






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 10 at 11:38

























asked Nov 9 at 16:08









Peter

11418




11418












  • Without looking at your code, I am just assuming there is something worng with channels. Perhaps you only apply the code to a single channel at some point, or you dont consider BGR-RGB conversions, or some other thing related to that.
    – Ander Biguri
    Nov 9 at 16:18










  • You should probably run that function with some code added that displays intermediate images. Compare those to your expectation of what they should look like, to narrow down where within the function it goes wrong.
    – Cris Luengo
    Nov 10 at 6:18


















  • Without looking at your code, I am just assuming there is something worng with channels. Perhaps you only apply the code to a single channel at some point, or you dont consider BGR-RGB conversions, or some other thing related to that.
    – Ander Biguri
    Nov 9 at 16:18










  • You should probably run that function with some code added that displays intermediate images. Compare those to your expectation of what they should look like, to narrow down where within the function it goes wrong.
    – Cris Luengo
    Nov 10 at 6:18
















Without looking at your code, I am just assuming there is something worng with channels. Perhaps you only apply the code to a single channel at some point, or you dont consider BGR-RGB conversions, or some other thing related to that.
– Ander Biguri
Nov 9 at 16:18




Without looking at your code, I am just assuming there is something worng with channels. Perhaps you only apply the code to a single channel at some point, or you dont consider BGR-RGB conversions, or some other thing related to that.
– Ander Biguri
Nov 9 at 16:18












You should probably run that function with some code added that displays intermediate images. Compare those to your expectation of what they should look like, to narrow down where within the function it goes wrong.
– Cris Luengo
Nov 10 at 6:18




You should probably run that function with some code added that displays intermediate images. Compare those to your expectation of what they should look like, to narrow down where within the function it goes wrong.
– Cris Luengo
Nov 10 at 6:18












1 Answer
1






active

oldest

votes

















up vote
0
down vote













I found the problem. As Mr. @Ander Biguri and Mr. @Cris Luengo (Sorry if I'm assuming your gender) has told me, the problem was at



UIntVer.convertTo(UIntVer, CV_32FC3);
Scalar four = new Scalar(4);
Core.multiply(UIntVer, four, UIntVer);


in image_expand(). Apparently, for multiplying a Scalar value, you have to perform Core.split() to an image matrix, and apply the multiplication for each channel, then Core.merge() it. This is because Core.multiply() only deals with 1 channel at a time. I hope this helps other people finding trouble with Core.multiply().






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53229340%2flaplacian-pyramid-producing-weird-results%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    I found the problem. As Mr. @Ander Biguri and Mr. @Cris Luengo (Sorry if I'm assuming your gender) has told me, the problem was at



    UIntVer.convertTo(UIntVer, CV_32FC3);
    Scalar four = new Scalar(4);
    Core.multiply(UIntVer, four, UIntVer);


    in image_expand(). Apparently, for multiplying a Scalar value, you have to perform Core.split() to an image matrix, and apply the multiplication for each channel, then Core.merge() it. This is because Core.multiply() only deals with 1 channel at a time. I hope this helps other people finding trouble with Core.multiply().






    share|improve this answer

























      up vote
      0
      down vote













      I found the problem. As Mr. @Ander Biguri and Mr. @Cris Luengo (Sorry if I'm assuming your gender) has told me, the problem was at



      UIntVer.convertTo(UIntVer, CV_32FC3);
      Scalar four = new Scalar(4);
      Core.multiply(UIntVer, four, UIntVer);


      in image_expand(). Apparently, for multiplying a Scalar value, you have to perform Core.split() to an image matrix, and apply the multiplication for each channel, then Core.merge() it. This is because Core.multiply() only deals with 1 channel at a time. I hope this helps other people finding trouble with Core.multiply().






      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote









        I found the problem. As Mr. @Ander Biguri and Mr. @Cris Luengo (Sorry if I'm assuming your gender) has told me, the problem was at



        UIntVer.convertTo(UIntVer, CV_32FC3);
        Scalar four = new Scalar(4);
        Core.multiply(UIntVer, four, UIntVer);


        in image_expand(). Apparently, for multiplying a Scalar value, you have to perform Core.split() to an image matrix, and apply the multiplication for each channel, then Core.merge() it. This is because Core.multiply() only deals with 1 channel at a time. I hope this helps other people finding trouble with Core.multiply().






        share|improve this answer












        I found the problem. As Mr. @Ander Biguri and Mr. @Cris Luengo (Sorry if I'm assuming your gender) has told me, the problem was at



        UIntVer.convertTo(UIntVer, CV_32FC3);
        Scalar four = new Scalar(4);
        Core.multiply(UIntVer, four, UIntVer);


        in image_expand(). Apparently, for multiplying a Scalar value, you have to perform Core.split() to an image matrix, and apply the multiplication for each channel, then Core.merge() it. This is because Core.multiply() only deals with 1 channel at a time. I hope this helps other people finding trouble with Core.multiply().







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 10 at 15:17









        Peter

        11418




        11418






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53229340%2flaplacian-pyramid-producing-weird-results%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Schultheiß

            Verwaltungsgliederung Dänemarks

            Liste der Kulturdenkmale in Wilsdruff