Created
October 18, 2011 00:25
-
-
Save eduardolundgren/1294307 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I = imread('../assets/mixtexts1.bmp'); | |
% S = qtdecomp(I, .27); | |
% blocks = repmat(uint8(0),size(S)); | |
% for dim = [512 256 128 64 32 16 8 4 2 1]; | |
% numblocks = length(find(S==dim)); | |
% if (numblocks > 0) | |
% values = repmat(uint8(1), [dim dim numblocks]); | |
% values(2:dim,2:dim,:) = 0; | |
% blocks = qtsetblk(blocks,S,dim,values); | |
% end | |
% end | |
% blocks(end,1:end) = 1; | |
% blocks(1:end,end) = 1; | |
% imshow(I), figure, imshow(blocks,[]) | |
% function test | |
fhandle = @myfun; | |
S = qtdecomp(I,fhandle); | |
% S = qtdecomp(I,0.27); | |
blocks = repmat(uint8(0),size(S)); | |
for dim = [512 256 128 64 32 16 8 4 2 1]; | |
numblocks = length(find(S==dim)); | |
if (numblocks > 0) | |
values = repmat(uint8(1),[dim dim numblocks]); | |
values(2:dim,2:dim,:) = 0; | |
blocks = qtsetblk(blocks,S,dim,values); | |
end | |
end | |
blocks(end,1:end) = 1; | |
blocks(1:end,end) = 1; | |
imshow(I), figure, imshow(blocks,[]) | |
function A = myfun(I) | |
% I is the input matrix | |
% there are k number of image blocks in I | |
% each image block is m-by-m, m is unknown (but it's not important) | |
varI = logical(zeros(1,size(I,3))); % create the output logical matrix, it has k number of elements where k is the number of image blocks | |
threshold = 2.7; % variance threshold | |
for i = 1:size(varI,2) | |
var_cur = var(var(double(I(:,:,i))))/numel(I); % find the variance for the current image block | |
% If varI(i) = 1, this means we want to further split the current image block | |
varI(i) = logical(var_cur > threshold); % further split the block if the variance is above the threshold | |
end | |
A = varI; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment