【图像分割】基于四叉树图像分割matlab源码

``` %Reversible Data hiding using Quad tree decomposition and histogrma %shifting %using quad tree to increase the hiding capacity

clc; clear all; close all; z=1;

%--------------------reading the image------------------------ b=imread('goldhill.jpg'); I=rgb2gray(b); figure(1); imshow(I); title('original image'); [m,n]=size(I); figure(2); imhist(I); title('histogram of original image');

%--------------------quadtree decomposition---------------------

mindim=4; S = qtdecomp(I,@Split,mindim,@Predicate);

%-------------------showing the block representation------------

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;

figure(3); imshow(blocks,[]); title('decomposed image blocks');

%-------------------showing fullimage-----------------------------------

vals1 = repmat(uint8(0),size(S)); for dim = [512 256 128 64 32 16 8 4 2 1] [vals,r,c]=qtgetblk(I,S,dim);

numblocks = length(find(S==dim));

if (numblocks > 0)
values = repmat(uint8(1),[dim dim numblocks]); values(2:dim,2:dim,:) = vals(2:dim,2:dim,1:numblocks) ;

vals1 = qtsetblk(vals1,S,dim,values);

end end figure(4); imshow(vals1,[]); title('decomposed image');

%----------------inputting the message/data to be hide--------------------- hidedata=input('Enter the data to be hide'); %for manual input %celldata=textread('myfile.txt', '%s', 'whitespace', ''); %reading data from text file %hidedata=char(celldata); bindata=convertbinary(hidedata); %calling function to convert data to binary binarydata=bindata'; sizebinary=size(binarydata,1)*size(binarydata,2); bin=1; a=1; % %-------------------embedding data in the image blocks--------------------- vals5 = repmat(uint8(0),size(S)); pd=1; q=1; ind=1; recdata(sizebinary)=0; for h=1:sizebinary recdata(h)=0; end for dim = [512 256 128 64 32 16 8 4 2 1] [vals2,r,c]=qtgetblk(I,S,dim); numblocks = length(find(S==dim));

if (numblocks > 0)        
  values = repmat(uint8(1),[dim dim numblocks]);
  values1 = repmat(uint8(1),[dim dim numblocks]);
  full_hideimage = repmat(uint8(1),[dim dim numblocks]);
  values(1:dim,1:dim,:) = vals2(1:dim,1:dim,1:numblocks) ;
  %full_hideimage(1:dim,1:dim,:)=vals2(1:dim,1:dim,1:numblocks);
  for i=1:size(values,3)
                get_block=values(:,:,i);
                newblock=values(:,:,i);
                hide_image=values(:,:,i);
                recover_block=values(:,:,i);
                original=get_block;
                l_block=length(get_block);
                count(255)=0;

                for h=1:255
                   count(h)=0;

                end

               for k=1:255
                  for l=1:l_block
                       for j=1:l_block

                             if get_block(l,j)==k
                                count(k)=count(k)+1;
                            end
                       end
                  end
               end
                [C,max_point]=max(count);
                [C1,min_point]=min(count);




               for l=1:l_block
                   for j=1:l_block
                        if (get_block(l,j)>min_point)&&(get_block(l,j)<max_point)
                            newblock(l,j)=get_block(l,j)+1;

                       elseif get_block(l,j)==(max_point+1)
                            newblock(l,j)=get_block(l,j)+1;

                        else
                            newblock(l,j)=get_block(l,j);
                        end
                   end
               end




            for l=1:l_block
                for j=1:l_block
                    if (newblock(l,j)==max_point)

                          if  (bin<=size_binary)
                               dat=binary_data(bin);

                                if dat==dec2bin(1)

                                       hide_image(l,j)=newblock(l,j)+ 1;
                                else
                                       hide_image(l,j)=newblock(l,j);
                                end
                          else
                            hide_image(l,j)=newblock(l,j);
                          end
                          bin=bin+1;

                    else
                    hide_image(l,j)=newblock(l,j);
                    end
                end
            end
            full_hideimage(:,:,i)=hide_image;
  end
  %------------showing data hided image---------------
values(1:dim,1:dim,1:numblocks)=full_hideimage(1:dim,1:dim,1:numblocks);
vals5 = qtsetblk(vals5,S,dim,values);
end

end

figure(5); imshow(vals5,[]); title('data hided image'); ```

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Matlab科研辅导帮

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值