KDOXG

roi

Nov 2nd, 2020
1,022
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×