Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function out = roi(filename,args)
- out = "";
- if typeinfo(args) == "string"
- in = imread(filename);
- mask = imread(args);
- result = in .* mask;
- imwrite(result,"result.png");
- out = "result.png";
- return
- else
- if length(args) != 2 || length(args(:,:)) != 2
- return
- endif
- in = imread(filename);
- pointA = args(1,:);
- pointB = args(2,:);
- if (pointA(1) < 0 || pointB(1) < 0 || pointA(2) < 0 || pointB(2) < 0
- || pointA(1) >= columns(in) || pointA(2) >= rows(in)
- || pointB(1) >= columns(in) || pointB(2) >= rows(in))
- return
- endif
- pointA = pointA + 1;
- pointB = pointB + 1;
- mask_temp = ones(pointB(2)-pointA(2)+1,pointB(1)-pointA(1)+1);
- mask = zeros(rows(in),columns(in));
- mask(pointA(2):pointB(2),pointA(1):pointB(1)) = mask_temp;
- result = in .* mask;
- imwrite(result,"result.png");
- out = "result.png";
- endif
- endfunction
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement