clear all;
close all;
clc;
p = imread('c:\snehal\pic.jpg');
p=imresize(p,[128,128]);
subplot(2, 2, 1:2);
imshow(p);
title('Original');
[row col plane]=size(p);
p=double(p);
% calculating global avg of each block
block=64;
tiilx=row-block;
tilly=col-block;
totalcnt=1;
factorx=0;
factory=0;
TotalBlock=(row/block)^2;
TotalBlock;
Gavg = zeros(TotalBlock,3);
TotalBlock=1;
Gavg(TotalBlock,1)=0;
for x=1:block:tiilx+1
for y=1:block:tilly+1
for i=x:(x+block-1)
for j=y:(block+y-1)
Gavg(TotalBlock,1)=(p(i,j,1)+Gavg(TotalBlock,1));
Gavg(TotalBlock,2)=(p(i,j,2)+Gavg(TotalBlock,2));
Gavg(TotalBlock,3)=(p(i,j,3)+Gavg(TotalBlock,3));
end
end
TotalBlock=TotalBlock+1
end
end
TotalBlock=TotalBlock-1
divideFactor=block*block;
for x=1:TotalBlock
for i=1:3
Gavg(x,i)=round(Gavg(x,i)/divideFactor);
end
end
disp(Gavg)
% till here
TotalBlock=(row/block)^2;
info=zeros(TotalBlock,6);
TotalBlock=1
np=zeros(row,col,3)
%% Red component
largecnt=0;
scnt=0;
tlarge=0;
ts=0;
Lavg=0;
Savg=0;
TotalBlock=1
for x=1:block:tiilx+1
for y=1:block:tilly+1
for i=x:(x+block-1)
for j=y:(block+y-1)
TotalBlock;
if p(i,j,1) > Gavg(TotalBlock,1)
largecnt= p(i,j,1)+largecnt;
tlarge=tlarge+1;
np(i,j,1)=1;
else
scnt=p(i,j,1)+scnt;
ts=ts+1;
np(i,j,1)=0;
end
end
end
tlarge=tlarge-1;
ts=ts-1;
Lavg=largecnt/tlarge;
Savg=scnt/ts;
info(TotalBlock,1)=Lavg;
info(TotalBlock,2)=Savg;
TotalBlock=TotalBlock+1
tlarge=0
ts=0
largecnt=0;
scnt=0;
end
end
TotalBlock=1
largecnt=0;
scnt=0;
tlarge=0;
ts=0;
Lavg=0;
Savg=0;
% Green component
for x=1:block:tiilx+1
for y=1:block:tilly+1
for i=x:(x+block-1)
for j=y:(block+y-1)
TotalBlock;
if p(i,j,2) > Gavg(TotalBlock,2)
largecnt= p(i,j,2)+largecnt;
tlarge=tlarge+1;
np(i,j,2)=1;
else
scnt=p(i,j,2)+scnt;
ts=ts+1;
np(i,j,2)=0;
end
end
end
tlarge=tlarge-1;
ts=ts-1;
Lavg=largecnt/tlarge;
Savg=scnt/ts;
info(TotalBlock,3)=Lavg;
info(TotalBlock,4)=Savg;
TotalBlock=TotalBlock+1
tlarge=0
ts=0
largecnt=0;
scnt=0;
end
end
TotalBlock=1
largecnt=0;
scnt=0;
tlarge=0;
ts=0;
Lavg=0;
Savg=0;
% Blue component
for x=1:block:tiilx+1
for y=1:block:tilly+1
for i=x:(x+block-1)
for j=y:(block+y-1)
TotalBlock;
if p(i,j,3) > Gavg(TotalBlock,3)
largecnt= p(i,j,3)+largecnt;
tlarge=tlarge+1;
np(i,j,3)=1;
else
scnt=p(i,j,3)+scnt;
ts=ts+1;
np(i,j,3)=0;
end
end
end
tlarge=tlarge-1;
ts=ts-1;
Lavg=largecnt/tlarge;
Savg=scnt/ts;
info(TotalBlock,5)=Lavg;
info(TotalBlock,6)=Savg;
TotalBlock=TotalBlock+1
tlarge=0
ts=0
largecnt=0;
scnt=0;
end
end
TotalBlock=1
disp(info);
% Final Image
for x=1:block:tiilx+1
for y=1:block:tilly+1
for i=x:(x+block-1)
for j=y:(block+y-1)
TotalBlock;
if np(i,j,1) ==1
np(i,j,1)=info(TotalBlock,1);
else
np(i,j,1)=info(TotalBlock,2);
end
if np(i,j,2) ==1
np(i,j,2)=info(TotalBlock,3);
else
np(i,j,2)=info(TotalBlock,4);
end
if np(i,j,3) ==1
np(i,j,3)=info(TotalBlock,5);
else
np(i,j,3)=info(TotalBlock,6);
end
end
end
TotalBlock=TotalBlock+1
end
end
np=uint8(np);
subplot(2, 2, 3:4);
imshow(np);
Title('Output Image');
刘良运
- 粉丝: 77
- 资源: 1万+
最新资源
- CardExpiredException解决方案(亲测可用).md
- python《Hybrid-SORT-多目标跟踪器(弱线索对在线多目标跟踪)》+项目源码+文档说明
- aspose:word,pdf,ppt
- 个人信用报告690428.zip
- 植物大战僵尸射击版v.0.3 双端安装程序
- 【重磅,更新!】中国各省水资源分类统计数据(2003-2022年)
- 富士施乐打印机驱动下载 适用机型:FujiXerox DocuPrint M375 df、M378 d、M378 df
- python-图片批量保存脚本
- aspose:word,pdf,ppt
- 中国2005-2021年大气污染物和二氧化碳排放趋势数据集【重磅,更新!】
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈