Main Content

qtsetblk

Set block values in quadtree decomposition

Description

J = qtsetblk(I,S,dim,vals) replaces each dim-by-dim block in the quadtree decomposition of image I with the corresponding block in vals. S contains the quadtree structure.

example

Examples

collapse all

Create a sample matrix representing a small image.

I = [1    1    1    1    2    3    6    6
     1    1    2    1    4    5    6    8
     1    1    1    1   10   15    7    7
     1    1    1    1   20   25    7    7
    20   22   20   22    1    2    3    4
    20   22   22   20    5    6    7    8
    20   22   20   20    9   10   11   12
    22   22   20   20   13   14   15   16];

Perform a quadtree decomposition of the image, specifying a threshold of 5. qtdecomp splits a block if the maximum value of the block elements minus the minimum value of the block elements is greater than the threshold.

S = qtdecomp(I,5);

Get the blocks of size 4-by-4 from the quadtree decomposition.

vals = qtgetblk(I,S,4);

Calculate the mode of each 4-by-4 block, and set all values to equal the mode.

valmodes = zeros(size(vals));
for blknum = 1:size(vals,3)
    valmodes(:,:,blknum) = mode(vals(:,:,blknum),'all');
end

Set the blocks in the image to the new values. The 4-by-4 blocks in the image are now homogenous.

J = qtsetblk(I,S,4,valmodes)
J = 8×8

     1     1     1     1     2     3     6     6
     1     1     1     1     4     5     6     8
     1     1     1     1    10    15     7     7
     1     1     1     1    20    25     7     7
    20    20    20    20     1     2     3     4
    20    20    20    20     5     6     7     8
    20    20    20    20     9    10    11    12
    20    20    20    20    13    14    15    16

Input Arguments

collapse all

Grayscale image, specified as a numeric matrix.

Data Types: single | double | int16 | uint8 | uint16 | logical

Quadtree structure, specified as a sparse matrix. If S(m,n) is nonzero, then the coordinate (m,n) is the upper left corner of a block in the decomposition, and the size of the block is given by S(m,n). You can get a quadtree structure by using the qtdecomp function.

Data Types: double

Block size, specified as a positive integer.

Block values, specified as a dim-by-dim-by-k array, where k is the number of dim-by-dim blocks in the quadtree decomposition.

The ordering of the blocks in vals must match the column-wise order of the blocks in I. For example, if vals is 4-by-4-by-2, then vals(:,:,1) contains the values used to replace the first 4-by-4 block in I, and vals(:,:,2) contains the values used to replace the second 4-by-4 block.

Version History

Introduced before R2006a

See Also

|