Advertisement
Hubert_M

Untitled

Jun 22nd, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.87 KB | None | 0 0
  1. % wczytanie obrazu znieksztaĹ?conego
  2. %colorInputImage = imread('20190314_103859.jpg');
  3. %colorInputImage = imresize(colorInputImage, 0.25);
  4. %imwrite(colorInputImage, 'test.bmp');
  5. colorInputImage = imread('Do.jpg');
  6. imshow(colorInputImage);
  7.  
  8. % konwersja do obrazu monochromatycznego
  9. grayInputImage = rgb2gray(colorInputImage);
  10. [height, width] = size(grayInputImage);
  11.  
  12. % punkty referencyjne w obrazie znieksztaĹ?conym
  13. Ap = [979; 854];
  14. Bp = [2095; 935];
  15. Cp = [2016; 3485];
  16. Dp = [288; 3163];
  17.  
  18. % punkty referencyjne w obrazie po korekcie
  19. margin = 50;
  20. A = [1+margin; 1+margin];
  21. B = [width-margin; 1+margin];
  22. C = [width-margin; height-margin];
  23. D = [1+margin; height-margin];
  24.  
  25. % wyznaczenie macierzy opisujÄ?cej znieksztaĹ?cenie
  26. W=[
  27. A(1), A(2), 1, 0, 0, 0, -A(1)*Ap(1), -A(2)*Ap(1);
  28. 0, 0, 0, A(1), A(2), 1, -A(1)*Ap(2), -A(2)*Ap(2);
  29. B(1), B(2), 1, 0, 0, 0, -B(1)*Bp(1), -B(2)*Bp(1);
  30. 0, 0, 0, B(1), B(2), 1, -B(1)*Bp(2), -B(2)*Bp(2);
  31. C(1), C(2), 1, 0, 0, 0, -C(1)*Cp(1), -C(2)*Cp(1);
  32. 0, 0, 0, C(1), C(2), 1, -C(1)*Cp(2), -C(2)*Cp(2);
  33. D(1), D(2), 1, 0, 0, 0, -D(1)*Dp(1), -D(2)*Dp(1);
  34. 0, 0, 0, D(1), D(2), 1, -D(1)*Dp(2), -D(2)*Dp(2)
  35. ];
  36.  
  37. V=[
  38. Ap(1);
  39. Ap(2);
  40. Bp(1);
  41. Bp(2);
  42. Cp(1);
  43. Cp(2);
  44. Dp(1);
  45. Dp(2)
  46. ];
  47.  
  48. X = W\V;
  49.  
  50. M = [X(1), X(2), X(3); X(4), X(5), X(6); X(7), X(8), 1]
  51.  
  52. % korekta obrazu
  53. colorOutputImage = zeros(height, width, 3);
  54.  
  55. for y=1:height
  56.   for x=1:width
  57.     P = [x; y; 1];
  58.     Pp = M*P;
  59.     xp = round(Pp(1)/Pp(3));
  60.     yp = round(Pp(2)/Pp(3));
  61.     if (xp >= 1) && (xp <= width) && (yp >=1) && (yp<=height)
  62.       colorOutputImage(y, x, 1) = colorInputImage(yp, xp, 1);
  63.       colorOutputImage(y, x, 2) = colorInputImage(yp, xp, 2);
  64.       colorOutputImage(y, x, 3) = colorInputImage(yp, xp, 3);
  65.     end
  66.   end
  67.   %printf('%d of %d\n', y, height);
  68.   %fflush(stdout);
  69. end
  70.  
  71. figure
  72. colorOutputImage = colorOutputImage/256;
  73. imshow(colorOutputImage);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement