Advertisement
KDOXG

roi

Nov 2nd, 2020
3,892
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Octave 0.92 KB | None | 0 0
  1. function out = roi(filename,args)
  2.   out = "";
  3.   if typeinfo(args) == "string"
  4.     in = imread(filename);
  5.     mask = imread(args);
  6.     result = in .* mask;
  7.     imwrite(result,"result.png");
  8.     out = "result.png";
  9.     return
  10.   else
  11.     if length(args) != 2 || length(args(:,:)) != 2
  12.       return
  13.     endif
  14.     in = imread(filename);
  15.     pointA = args(1,:);
  16.     pointB = args(2,:);
  17.     if (pointA(1) < 0 || pointB(1) < 0 || pointA(2) < 0 || pointB(2) < 0
  18.     || pointA(1) >= columns(in) || pointA(2) >= rows(in)
  19.     || pointB(1) >= columns(in) || pointB(2) >= rows(in))
  20.       return
  21.     endif
  22.     pointA = pointA + 1;
  23.     pointB = pointB + 1;
  24.     mask_temp = ones(pointB(2)-pointA(2)+1,pointB(1)-pointA(1)+1);
  25.     mask = zeros(rows(in),columns(in));
  26.     mask(pointA(2):pointB(2),pointA(1):pointB(1)) = mask_temp;
  27.     result = in .* mask;
  28.     imwrite(result,"result.png");
  29.     out = "result.png";
  30.   endif
  31. endfunction
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement