Please tell me how to resolve out of memory error of this code
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
count = 1; j = 1; matrix=[];
while(j+63<m) k = 1; while(k+63<n) dum=zeros(1,64*64); dum(1:(min(m-j+1,64)*(min(n-k+1,64))))=reshape(img1(j:min(j+63,m),k:min(n,k+63)),1,(min(m-j+1,64)*(min(n-k+1,64)))); matrix = [matrix;j,k,dum]; count = count+1; k = k+1; end j = j+1; end
採用された回答
Hi,
assuming that the out of memory happens in the assignment
matrix = [matrix; j,k,dum];
I would suggest to preallocate matrix. Compute the number of rows matrix will have - something like (m-63)*(n-63) - and preallocate
matrix = zeros((m-63)*(n-63), 2+64*64);
Instead of
matrix = [matrix; j,k,dum];
you write
matrix(count, :) = [j k dum];
If the preallocation works (depends on m, n of course), then the rest should work.
Titus
8 件のコメント
I Have done this but in that case it is giving error "Maximum variable size allowed by the program is exceeded" in line matrix = zeros((m-63)*(n-63), 2+64*64);
Then I guess m and n are rather large? What are they?
It's 500*500 image. so size of m=n=500
shikha gautam
2015 年 1 月 7 日
編集済み: shikha gautam
2015 年 1 月 7 日
This is the complete code :
img=rgb2gray(imread('16.jpg')); img1=double(img).*1/256; i=1; [m,n]=size(img); N = m*n;
%initialisation b = 64; Nbp = (sqrt(m) - sqrt(b) + 1)^(sqrt(n)-sqrt(b)+1); Nb = ceil(Nbp); epsilon = 0.01; Q = 256; Nn = 1; Nf = 64; Nd = 100; count = 1; j = 1; matrix = zeros((m-63)*(n-63), 2+64*64);
while(j+63<m) k = 1; while(k+63<n) dum=zeros(1,64*64); dum(1:(min(m-j+1,64)*(min(n-k+1,64))))=reshape(img1(j:min(j+63,m),k:min(n,k+63)),1,(min(m-j+1,64)*(min(n-k+1,64)))); matrix(count, :) = [j k dum]; count = count+1; k = k+1; end j = j+1; end
%matrix = a/Q S= sortrows(matrix,(3:64*64+2)); [r, c] = size(S); list = zeros(r,4); count = 1; for j=1:r for k= j+1:min(r,j+Nn) if(k-r<=Nn) temp = [S(j,1), S(j,2), S(k,1), S(k,2)]; list(count,:) = temp; count = count+1; end end end black = 0; for j=1:count-1 temp = list(j, :); if (64*floor(sqrt((temp(1)-temp(3))^2 + (temp(4)-temp(2))^2)) < Nd) %make the pixel values of these zero %presently seems wrong to me or maybe its right black = black+1; x1 = list(j, 1); y1 = list(j, 2); x2 = list(j, 3); y2 = list(j, 4); img(64*(x1-1)+1:min(64*x1,m),64*(y1-1)+1:min(n,64*y1))= 0; img(64*(x2-1)+1:min(64*x2,m),64*(y2-1)+1:min(n,64*y2))= 0; end end disp(black) imshow(uint8(img));
As in the new thread stated: your matrix would be (500-63)*(500-63)*(2+64*64)*8 bytes = 6GB large ...
Titus
It requires a huge memory for this. Please help me in this code to run this .
There is not much I can offer: your result is too large to fit into memory. So you need to rethink if you need to store the result like this? What do you do with it later? You don't do the calculation for fun I guess, so the question is how to proceed without storing all the matrices...
I am using this code to detect forgery in a image. for which I have to do so. we divide the image into non-overlapping blocks and then we lexicographically sort them. After sorting, we take lexicographically "close" blocks and compute the distance between their positions. If the distance is less than a minimum threshold, then we mark both the blocks as manipulated blocks
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Creating and Concatenating Matrices についてさらに検索
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
