【图像分割】基于matlab四叉树图像分割【含Matlab源码 091期】
一、获取代码方式
获取代码方式1:
通过订阅紫极神光博客付费专栏,凭支付凭证,私信博主,可获得此代码。
获取代码方式2:
通过紫极神光博客主页开通CSDN会员,凭支付凭证,私信博主,可获得此代码。
获取代码方式3:
完整代码已上传我的资源:【图像分割】基于matlab四叉树图像分割【含Matlab源码 091期】
备注:开通CSDN会员,仅只能免费获得1份代码(有效期为开通日起,三天内有效);
订阅紫极神光博客付费专栏,可免费获得1份代码(有效期为订阅日起,三天内有效);
二、四叉树图像分割简介
1 图割概述
图像分割问题从本质上来说是像素分配的问题, 也可以说是像素的标记问题。给定一个标签集合L, 图像中的一个像素为Pi (i=1, 2, …, n) , 图像分割就是对图像中的每一个像素分配一个标签Pi∈Lo或者Pi∈Lp (Lo为目标, Lp为背景) 的过程。图割是基于图论的一种方法, 首先将一幅图像映射为一个网络图G= (V, E) , 在这个图中有两类节点, 即普通节点Pi, 端节点S和T, 其中S为前景目标, T为背景目标。边E={ (u, v) |u∈P, v∈P}表示图中边的集合, 一般的图割方法中只有相邻的节点间才存在边, 每条边上都有权值ω (u, v) 。所要解决的问题就是在已知能量函数的前提下, 如何将这个图切割开, 并且隔开后所花的代价最小。G1, G2为被割开后的子图。
2 四叉树分割方法
令G表示一幅图像, 将G分割成n个子区域G1, G2, ···, Gn的过程就叫分割, 满足的条件如下:
(2) Gi (i=1, 2, …, n) 是一个连通域;
(5) P (Gi∪Gj) =FALSE, 对于任意相邻像素Gi和Gj。
其中, P (Gi) 是定义在集合Gi的点上的逻辑谓词, 表示空集。
四叉树的分解步骤如下:
(1) 将原图像分成几个 (一般为4个) 大小相同的区域。
(2) 将所分图像的每个区域依次判定是否满足判定标准, 如果不满足, 就将这个区域继续细分, 直到所有的区域都满足这个评判标准为止。使用的评判标准为, 同一区域内像素值的方差不超过某个阈值, 即S (Ri) <A, A越小, 分割的区域精度就越高, 算法执行的时间也就越长, 反之亦然。
(3) 使用像素点合并的方法, 合并孤立的像素点。
(4) 迭代重复上述过程, 直到所有的区域都符合评判标准。
三、部分源代码
%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---------------------
hide_data=input('Enter the data to be hide'); %for manual input
%cell_data=textread('myfile.txt', '%s', 'whitespace', ''); %reading data from text file
%hide_data=char(cell_data);
bin_data=convert_binary(hide_data); %calling function to convert data to binary
binary_data=bin_data';
size_binary=size(binary_data,1)*size(binary_data,2);
bin=1;
a=1;
% %-------------------embedding data in the image blocks---------------------
vals5 = repmat(uint8(0),size(S));
pd=1;
q=1;
ind=1;
rec_data(size_binary)=0;
for h=1:size_binary
rec_data(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');
- 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
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
- 129
- 130
- 131
- 132
- 133
- 134
- 135
- 136
- 137
- 138
- 139
- 140
- 141
- 142
- 143
- 144
- 145
- 146
- 147
- 148
- 149
- 150
- 151
- 152
- 153
- 154
- 155
- 156
- 157
- 158
- 159
- 160
- 161
- 162
- 163
- 164
- 165
- 166
- 167
- 168
- 169
- 170
- 171
- 172
- 173
- 174
四、运行结果
五、matlab版本及参考文献
1 matlab版本
2014a
2 参考文献
[1] 蔡利梅.MATLAB图像处理——理论、算法与实例分析[M].清华大学出版社,2020.
[2]杨丹,赵海滨,龙哲.MATLAB图像处理实例详解[M].清华大学出版社,2013.
[3]周品.MATLAB图像处理与图形用户界面设计[M].清华大学出版社,2013.
[4]刘成龙.精通MATLAB图像处理[M].清华大学出版社,2015.
[5]陈浩,方勇,朱大洲,王成,陈子龙.基于蚁群算法的玉米植株热红外图像边缘检测[J].农机化研究. 2015,37(06)
文章来源: qq912100926.blog.csdn.net,作者:海神之光,版权归原作者所有,如需转载,请联系作者。
原文链接:qq912100926.blog.csdn.net/article/details/112461424
- 点赞
- 收藏
- 关注作者
评论(0)