Results 1 to 6 of 6

Thread: Convolution filter

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2008
    Location
    France
    Posts
    149
    Thanks
    2
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Convolution filter

    Hello,

    I need to implement an edge dectection filter on an image.

    i've managed to put all the Qrgb colors of the image in a table (matrice_pixel[height] [width] ).

    My filter is kernel[3][3] .

    But i can't get it work properly when i mutiply the two tables.

    Any idea?

    Qt Code:
    1. QRgb **matrice_pixel = new QRgb*[height];
    2. for (int i = 0; i <height; i++){
    3. matrice_pixel[i] = new QRgb[width];
    4. }
    5.  
    6. /// Getting the colors
    7. for ( int i=0; i<height; i++ ) {
    8. uchar *p = source.scanLine(i);
    9. for (int j = 0; j< width;j ++) {
    10. int blue = int(*p++);
    11. int green = int(*p++);
    12. int red = int(*p++);
    13. int alpha = int(*p++);
    14. QRgb rgbValue = qRgba(red,green,blue, alpha);
    15. matrice_pixel[i][j] = rgbValue;
    16. }
    17.  
    18. for (int x = 1; x<width ;++x)
    19. {
    20. for (int y= 1; y< height; ++y)
    21. {
    22. int red = 0, green = 0, blue = 0;
    23. //multiply every value of the filter with corresponding image pixel
    24. for(int kernelX = 0; kernelX < kernelWidth; kernelX++)
    25. {
    26. for(int kernelY = 0; kernelY < kernelHeight; kernelY++){
    27.  
    28. red += qRed(matrice_pixel[x][ y] ) * kernel[kernelX][kernelY];
    29. green += qGreen(matrice_pixel[x][y]) * kernel[kernelX][kernelY];
    30. blue += qBlue(matrice_pixel[x] [ y]) * kernel[kernelX][kernelY];
    31. }
    32. //truncate values smaller than zero and larger than 255
    33. red = qMin(qMax(int(factor * red + bias), 0), 255);
    34. green= qMin(qMax(int(factor * green + bias), 0), 255);
    35. blue= qMin(qMax(int(factor * blue + bias), 0), 255);
    36. QRgb rgbValue = qRgb(red,green,blue);
    37. img.setPixel(x,y, rgbValue);
    38.  
    39. }
    40. }
    41. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by wysota; 20th October 2009 at 19:47. Reason: missing [code] tags

Similar Threads

  1. Q3Table event filter problem
    By batileon in forum Qt Programming
    Replies: 2
    Last Post: 27th August 2008, 10:40
  2. Optimizing filterAcceptsRow() to filter a tree
    By vfernandez in forum Qt Programming
    Replies: 1
    Last Post: 4th January 2007, 12:50
  3. Replies: 9
    Last Post: 31st March 2006, 13:07
  4. filter processEvents
    By sreedhar in forum Qt Programming
    Replies: 1
    Last Post: 23rd March 2006, 11:16
  5. Replies: 9
    Last Post: 5th March 2006, 03:31

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.