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');
刘良运
- 粉丝: 80
- 资源: 1万+
最新资源
- 电信口令兑换0.88~100亓话费.mp4
- 抖店精细化运营详细的精细化运营抖店玩法.mp4
- 抖看小说app 覆盖各类题材.mp4
- 抖音快手小红书养号工具,安卓手机通用不限制数量,截流自热必备养号神器解放双手.mp4
- C语言实践作业飞机大战.zip
- 抖音热门华语劲爆车载DJ歌曲合集.mp4
- 抖音评论采集抓取获客系统v2.4.mp4
- 基于Android Studio开发的安卓的音乐播放器app源码+报告(安卓期末大作业)
- 抖音小红书留微信不屏蔽生成工具.mp4
- 独居治愈系视频制作,日变现多张,多平台发布(抖音、视频号、小红书).mp4
- 短视频上热门的20个流量密码实战案例.mp4
- 多邻国语言Duolingo v6.10.4.0解锁vip付费版.mp4
- 发光霓虹灯文字闪烁特效源码.mp4
- 番茄小说领券0.01亓撸书本等.mp4
- 锂电池项目 欧姆龙NJ501-1400系列plc程序 自动二封机,PLC程序,无触摸屏程序 1.松下A6系列总线伺服驱动器控制,位置模式控制 2.雷赛总线节点步进电机控制,参数读写,电流,极性,感应器
- 饭团追书app 拥有非常多的分类.mp4
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈