Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: i want to simplify this code
Replies: 14   Last Post: Apr 22, 2013 7:11 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
mohammed

Posts: 18
From: egypt
Registered: 12/10/07
Re: i want to simplify this code
Posted: Apr 7, 2013 5:18 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

this is the full code

clear
I = imread('me.jpg');
I=imresize(I,[256 256]);
I=rgb2gray(I);
I = im2double(I);
S = qtdecomp(I,.40);
T2 = dctmtx(2);
T4 = dctmtx(4);
T8 = dctmtx(8);
T16 = dctmtx(16);
T32 = dctmtx(32);
T64 = dctmtx(64);
T0=dctmtx(1);
mask8 = zeros(8);
mask8(1,1:4)=1;
mask8(2,1:3)=1;
mask8(3,1:1)=1;
mask16 =zeros(16);
mask16(1:5,1:2)=1;
mask16(1:2,3:4)=1;
mask16(1,5:8)=1;
mask32 =zeros(32);
mask32(1:16,1:2)=1;
mask32(1:10,1:4)=1;
mask32(1:4,5:8)=1;
mask32(1:2,9:16)=1;
mask64 =zeros(64);
mask64(1:16,1:2)=1;
mask64(1:10,1:4)=1;
mask64(1:4,5:8)=1;
mask64(1:2,9:16)=1;


mask4 = [1 1 1 1
1 1 1 0
1 0 0 0
0 0 0 0 ];
mask2 = [1 1
1 1 ];
mask01 = [1];
All= zeros(size(I));


[x2,y2,z2]=find(S==2);
for n2=1:length(x2)
B1=T2* I(x2(n2):x2(n2)+1,y2(n2):y2(n2)+1)* T2';
R1=B1.*mask2;
F1=T2'*R1*T2;
All(x2(n2):x2(n2)+1,y2(n2):y2(n2)+1)=F1;
end



[x4,y4,z4]=find(S==4);
for n4=1:length(x4)
B2=T4*I(x4(n4):x4(n4)+3,y4(n4):y4(n4)+3)*T4';
R2=B2.*mask4;
F2=T4'*R2*T4;
All(x4(n4):x4(n4)+3,y4(n4):y4(n4)+3)=F2;

end
[x8,y8,z8]=find(S==8);
for n8=1:length(x8)
B8=T8*I(x8(n8):x8(n8)+7,y8(n8):y8(n8)+7)*T8';
R8=B8.*mask8;
F8=T8'*R8*T8;
All(x8(n8):x8(n8)+7,y8(n8):y8(n8)+7)=F8;

end

[x0,y0,z0]=find(S==1);
for n=1:length(x0)
B0= T0 * I(x0(n),y0(n)) * T0';

All(x0(n),y0(n))=B0;
end

[x16,y16,z16]=find(S==16);
for n16=1:length(x16)
B3= T16 * I(x16(n16):x16(n16)+15,y16(n16):y16(n16)+15) * T16';
R4 = B3 .* mask16;
F4 = T16' * R4 * T16;
All(x16(n16):x16(n16)+15,y16(n16):y16(n16)+15)=F4;
end


[x32,y32,z32]=find(S==32);
for n32=1:length(x32)
B4= T32* I(x32(n32):x32(n32)+31,y32(n32):y32(n32)+31) * T32';
R5= B4 .* mask32;
F5 = T32' * R5 * T32 ;
All(x32(n32):x32(n32)+31,y32(n32):y32(n32)+31)=F5;
end

[x64,y64,z64]=find(S==64);
for n64=1:length(x64)
B5=T64 * I(x64(n64):x64(n64)+63,y64(n64):y64(n64)+63) * T64';
R6=B5.* mask64;
F6= T64' * R6 * T64 ;

All(x64(n64):x64(n64)+63,y64(n64):y64(n64)+63)=F6;
end


imshow(I)



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.