Advertisement
riyanris

Untitled

Sep 18th, 2020
1,653
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.92 KB | None | 0 0
  1. %Read the image
  2. img = imread('course1image.jpg');
  3. B=img(1:341,1:400);
  4. G=img(342:682,1:400);
  5. R=img(683:1023,1:400);
  6. b=double(B);
  7. g=double(G);
  8. r=double(R);
  9. b1=double(b(146:196,175:225));
  10. g1=double(g(146:196,175:225));
  11. r1=double(r(146:196,175:225));
  12. ref_img_region = double(g1);
  13. ref_img_region = double(ref_img_region);
  14. error = inf;
  15. for i = -10:10
  16. for j = -10:10
  17. shiftr1=circshift(r1,[i,j]);
  18. temp1 = sum(sum((double(g1) - double(shiftr1)) .^ 2));
  19. if temp1 < error
  20. error = temp1;
  21. shiftr_row = i;
  22. shiftr_col = j;
  23. end
  24. end
  25. end
  26. error = inf;
  27. for i = -10:10
  28. for j = -10:10
  29. shiftb2=circshift(b1,[i,j]);
  30. temp2 = sum(sum((double(g1) - double(shiftb2)) .^ 2));
  31. if temp2 < error
  32. error = temp2;
  33. shiftb_row = i;
  34. shiftb_col = j;
  35. end
  36. end
  37. end
  38. shiftr=circshift(r,[shiftr_row,shiftr_col]);
  39. shiftb=circshift(b,[shiftb_row,shiftb_col]);
  40. ColorImg_aligned=cat(3,uint8(shiftr),uint8(g),uint8(shiftb));
  41. imshow(ColorImg_aligned)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement