matlab code not working for 64x64 dct block

I have implemented 2d dct code which is working for (4x4 ,8x8,16x16)block but its not working for 64x64 block ,in matlab its showing busy for more than 1 hour,what changes i should do to get the desired result.
for N = [8];
C = zeros(N,N);
for m = 0:1:N-1
for n = 0:1:N-1
if n == 0
k = sqrt(1/N);
else
k = sqrt(2/N);
end
C(m+1,n+1) = k*cos( ((2*m+1)*n*pi) / (2*N));
end
end
% Get Basis Functions
figure;
colormap('gray');
for m = 0:1:N-1
for n = 0:1:N-1
subplot(N,N,m*N+n+1);
Y = [zeros(m,N);
zeros(1,n) 1 zeros(1,N-n-1);
zeros(N-m-1,N)];
X = C*Y*C';
imagesc(X);
axis square;
axis off;
end
end
end
Please help i m trying a lot.

댓글 수: 2

What's the point of this for loop:
for N = [8];
.....
end
You don't need a for loop to execute just one time with N=8. Just set N=8, and don't have a for loop.
Joseph Cheng
Joseph Cheng 2015년 6월 16일
What i take out of the for N= [8] is that this person was looking to perform this section of code on for N=[2 4 8 16 ... 64]

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2015년 6월 15일

0 개 추천

The code finishes in a small number of seconds when I try it.

댓글 수: 5

@Walter Roberson my code is not working.
Joseph Cheng
Joseph Cheng 2015년 6월 15일
편집: Joseph Cheng 2015년 6월 15일
you probably do not have enough memory in your system to generate 64x64 subplots. what you can do is preallocate and index them and put them together like below
figure;
colormap('gray');
X = zeros(64*64,64*64);
for m = 0:1:N-1
for n = 0:1:N-1
disp([m n])
Y = zeros(N,N);
Y(m+1,n+1) = 1;
X(m*64+1:(m+1)*64,n*64+1:(n+1)*64) = C*Y*C';
axis square;
axis off;
end
end
x = linspace(0,64,64*64);
imagesc(x,x,X),colormap(gray),axis equal, axis tight, grid on
set(gca,'ytick',0:64)
set(gca,'xtick',0:64)
also i simplified what you were trying to do when creating Y.
I copied your exact code and it worked fine on my R2014a system. It took about 0.8 seconds to execute.
Joseph Cheng
Joseph Cheng 2015년 6월 15일
편집: Joseph Cheng 2015년 6월 15일
Walter the code above works fine but the problem is going up and up for N=64 such that the block of data is 64x64. the code above is the 8x8 case (line 1)
Ah yes, it does take a long time to build the 4096 individual plots.
The C matrix generation could obviously be optimized some, but that probably does not matter compared to the plot time.
[mg, ng] = ngrid(0:1:N-1);
k = sqrt(2/N);
C = k .* cos( ((2*mg+1) .* ng .* pi) ./ (2*N));
C(:,1) = C(:,1) ./ sqrt(2);
That is, build it all using the larger k, and then correct the first column which is now sqrt(2) too large. k*cos( ((2*m+1)*n*pi) / (2*N));

댓글을 달려면 로그인하십시오.

질문:

2015년 6월 12일

댓글:

2015년 6월 17일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by