No Description

filter.cpp 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #include "mainwindow.h"
  2. #include <QImage>
  3. ///
  4. /// Function that applies a greyscale filter to the edited image.
  5. /// It works by turning each pixel into the color grey. For this we use
  6. /// two for loops to access the pixels of the edited image.
  7. ///
  8. void MainWindow::GrayScale(QImage &editedImage){
  9. // Space to implement the grayscale filter.
  10. // YOUR CODE HERE
  11. }
  12. ///
  13. /// Function that applies a vertical flip to the edited image.
  14. /// For this we use two for loops to access the pixels of the images.
  15. /// In the first loop we go through the x axis and in the second we go
  16. /// through the y axis and inside of it we put the pixel from the original
  17. /// image in the heigth-1-j position of the edited image.
  18. ///
  19. void MainWindow::VerticalFlip(QImage &editedImage){
  20. unsigned int width = editedImage.width();
  21. unsigned int height = editedImage.height();
  22. unsigned int reverseY;
  23. QRgb pixel, pixelRev;
  24. for(unsigned int x = 0; x < width ; x++) {
  25. for(unsigned int y = 0; y < height / 2; y++){
  26. reverseY = height - 1 - y;
  27. pixel = editedImage.pixel(x,y);
  28. pixelRev = editedImage.pixel(x,reverseY);
  29. editedImage.setPixel(x,reverseY,pixel);
  30. editedImage.setPixel(x,y,pixelRev);
  31. }
  32. }
  33. }
  34. ///
  35. /// Function that applies a horizontal flip to the edited image
  36. /// For this we use two for loops to access the pixels of the images.
  37. /// In the first loop we go through the x axis and in the second we go
  38. /// through the y axis and inside of it we put the pixel from the original
  39. /// image in the width-1-i position of the edited image.
  40. ///
  41. void MainWindow::HorizontalFlip(QImage &editedImage){
  42. unsigned int width = editedImage.width();
  43. unsigned int height = editedImage.height();
  44. unsigned int reverseX;
  45. QRgb pixel, pixelRev;
  46. for(unsigned int x = 0; x < width/2; x++) {
  47. reverseX = width - 1 - x;
  48. for(unsigned int y = 0; y < height; y++){
  49. pixel = editedImage.pixel(x,y);
  50. pixelRev = editedImage.pixel(reverseX,y);
  51. editedImage.setPixel(reverseX,y,pixel);
  52. editedImage.setPixel(x,y,pixelRev);
  53. }
  54. }
  55. }
  56. ///
  57. /// Function that applies a threshold filter to the edited image.
  58. /// For this we use two for loops to access the pixels of the images.
  59. /// In the first loop we go through the x axis and in the second we go
  60. /// through the y axis.
  61. ///
  62. void MainWindow::ThresholdFilter(QImage &originalImage, QImage &editedImage,
  63. unsigned int threshold, bool invertColor){
  64. // Space to implement the Threshold Filter.
  65. // threshold contains the treshold value
  66. // invertColor is a variable to flip from Black to White for pixel
  67. // over the threshold and viceversa.
  68. // YOUR CODE HERE
  69. }