-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsvd_block.m
More file actions
52 lines (33 loc) · 1.22 KB
/
svd_block.m
File metadata and controls
52 lines (33 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
function [imgOut, mask] = svd_block(imgIn, varargin);
% Find regions of irregular compression via SVD block decomposition
%% 0. Input Handling
% grayscale image and trim to a size divisible by init.blockDistance
if size(imgIn, 3) == 3
img_gray_full = rgb2gray(imgIn);
elseif size(imgIn, 3) == 1
warning('Image only has single channel: treating as grayscale');
img_gray_full = imgIn;
else
error('Image not RGB or single-channel')
end
assert(nargin <= 2, 'at most one varargin')
if nargin == 2
init = varargin{1};
assert(isa(init, 'svd_block_init'), ['varargin must be an' ...
'svd_block_init OBJECT']);
else
init = expand_block_init;
end
% area not divisible by blockDistance
overScan = mod(size(img_gray_full), init.blockDistance);
img = img_gray_full( 1: (end-overScan(1)) , 1:(end-overScan(2)) );
% trim off overscan area
% grayscale image and trim to a size divisible by init.blockDistance
%% 1: Divide an image into small overlapping blocks of blockSize^2
block = svd_blockMaker(img, init);
%% 2. For each block, compute the SVD:
block = find_block_svd(block);
%% 3. Process the SVDs
block = process_svd(block, init);
%% 4. Create Mask
mask = create_mask_svd(block, init, imgIn)