Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix : image/conv2 & dsp/conv, p_median3x3_f32 : hardwired network #148

Merged
merged 2 commits into from
Jun 16, 2015

Conversation

ebadi
Copy link
Contributor

@ebadi ebadi commented Jun 16, 2015

dsp/p_conv_f32: Remove an extra element in the result, Fix a problem in involving uninitialize memory addresses in computation.
image/p_conv2d_f32: Returns incorrect values as it doesn't flip the kernel in vertical and horizontal directions, Support for rectangular kernels.
image/p_median3x3.c: For 3x3 median filter, I replaced it with hardwired median search described here: http:users.utcluj.ro/~baruch/resources/Image/xl23_16.pdf
README.md: Typo

Counter example for p_conv_f32

Response from FreeMat:

--> x = [1, 2, 3, 4];
--> h = [5,6,7];
--> r = conv(x, h)
r =
  5 16 34 52 45 28 

Response from pal:
100.000000, 105.000000, 116.000000, 134.000000, 152.000000, 145.000000, 128.000000, 100.000000

   float x[4] = {1,2,3,4};
   float h[3] = {5,6,7} ;
   float r[10] = {100,100,100,100,100,100, 100, 100,100, 100};  
   p_conv_f32( x, h , r ,4 ,3);
   printf ("%f, %f, %f, %f, %f, %f, %f, %f", r[0], r[1], r[2], r[3], r[4], r[5], r[6], r[7]);

Counter example for p_conv2d_f32

Response from FreeMat:

--> A= [17 24 1 8 15; 23 5 7 14 16; 4 6 13 20 22;10 12 19 21 3; 11 18 25 2 9]
--> B=[1 3 1; 0 5 0; 2 1 2]
--> E=[0 0 0; 0 1 0; 0 0 0]
--> C2 = conv2(A,E,'valid')   <-- works correctly since kernel is symmetric   
--> C1 = conv2(A,B,'valid')   <-- Doesn't work correctly

120, 165, 205,
160, 200, 245,
190, 255, 235,

Response from pal:
155.0, 135.0, 200.0,
145.0, 190.0, 230.0,
185.0, 225.0, 270.0,

#define W 5
#define W2 (W-2)
int main(int argc, char *argv[])
{
   int i, j;
   float src[5*5] = {17,24,1,8,15,
                    23,5,7,14,16,
                    4,6,13,20,22,
                    10,12,19,21,3,
                    11,18,25,2,9 };
   float kernel[3*3] = {
          1,3,1,
          0,5,0,
          2,1,2 };
    float dest[3*3];
    p_conv2d_f32(src, kernel, dest, 5, 5, 3);

    for (i = 0; i < W; i++) {
        for (j = 0; j < W; j++) {       
            printf("%.1f, ", src[i*W+j]);
        }
        printf("\n");
    }

    printf("\n");

    for (i = 0; i < W2; i++) {
        for (j = 0; j < W2; j++) {
            printf("%.1f, ", dest[i*W2+j]);
        }
        printf("\n");
    }
}

Old pull request : #100

dsp/p_conv_f32: Remove an extra element in the result, Fix a problem in involving uninitialize memory addresses in computation.
image/p_conv2d_f32: Returns incorrect values as it doesn't flip the kernel in vertical and horizontal directions, Support for rectangular kernels.
image/p_median3x3.c: For 3x3 median filter, I replaced it with hardwired median search described here: http:users.utcluj.ro/~baruch/resources/Image/xl23_16.pdf

Extra information
    Signed-off-by: Hamid Ebadi <hamid.ebadi@gmail.com>

Counter example for p_conv_f32

Response from FreeMat:
--> x = [1, 2, 3, 4];
--> h = [5,6,7];
--> r = conv(x, h)
r =
  5 16 34 52 45 28

Response from pal:
   float x[4] = {1,2,3,4};
   float h[3] = {5,6,7} ;
   float r[10] = {100,100,100,100,100,100, 100, 100,100, 100};
   p_conv_f32( x, h , r ,4 ,3);
   printf ("%f, %f, %f, %f, %f, %f, %f, %f", r[0], r[1], r[2], r[3], r[4], r[5], r[6], r[7]);
   100.000000, 105.000000, 116.000000, 134.000000, 152.000000, 145.000000, 128.000000, 100.000000

Counter example for p_conv2d_f32

Response from FreeMat:
--> A= [17 24 1 8 15; 23 5 7 14 16; 4 6 13 20 22;10 12 19 21 3; 11 18 25 2 9]
--> B=[1 3 1; 0 5 0; 2 1 2]
--> E=[0 0 0; 0 1 0; 0 0 0]
--> C2 = conv2(A,E,'valid')   <-- works correctly since kernel is symmetric
--> C1 = conv2(A,B,'valid')   <-- Doesn't work correctly

120, 165, 205,
160, 200, 245,
190, 255, 235,

Response from pal:
155.0, 135.0, 200.0,
145.0, 190.0, 230.0,
185.0, 225.0, 270.0,

int main(int argc, char *argv[])
{
   int i, j;
   float src[5*5] = {17,24,1,8,15,
                    23,5,7,14,16,
                    4,6,13,20,22,
                    10,12,19,21,3,
                    11,18,25,2,9 };
   float kernel[3*3] = {
          1,3,1,
          0,5,0,
          2,1,2 };
    float dest[3*3];
    p_conv2d_f32(src, kernel, dest, 5, 5, 3);

    for (i = 0; i < W; i++) {
        for (j = 0; j < W; j++) {
        	printf("%.1f, ", src[i*W+j]);
        }
        printf("\n");
    }

    printf("\n");

    for (i = 0; i < W2; i++) {
        for (j = 0; j < W2; j++) {
        	printf("%.1f, ", dest[i*W2+j]);
        }
        printf("\n");
    }
}
Extra information
    Signed-off-by: Hamid Ebadi <hamid.ebadi@gmail.com>
@mateunho
Copy link
Contributor

For p_median3x3: duplicate of #132

@ebadi
Copy link
Contributor Author

ebadi commented Jun 16, 2015

No it is not duplicate of #132. I mentioned that 9day ago in #100 ; but it is not merged since then; Because of many changes in function signatures I decided to close that pull request and open a new pull request.

aolofsson added a commit that referenced this pull request Jun 16, 2015
Fix :  image/conv2  &  dsp/conv,   p_median3x3_f32 : hardwired network
@aolofsson aolofsson merged commit 07c9078 into parallella:master Jun 16, 2015
@mateunho
Copy link
Contributor

@ebadi sorry, my oversight.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants