필터 지우기
필터 지우기

Composing matrix from small matrices

조회 수: 4 (최근 30일)
bikekowal Marcin Kowalski
bikekowal Marcin Kowalski 2012년 6월 2일
Hi all,
I have a random matrix generated by a rand function. The matrix size is 60x60 (a small array). I want to resize this matrix up to 600 x 600 (let's call it big array). I want that every 10x10 pixels from the 'big array' was filled by a corresponding pixel from a small array. For example pixels (1:10, 1:10) from a big array would have a '1' if the small_array(1,1) equals '1'.
How to do that? I tried to treat this array as an image and use imresize funtion, but it gives blurred image. I also tried following code, but there is something missing and I dont know what it is exactly.
size = 60;
Phi = rand(size,size)>0.5;
BigPhi = zeros(600,600);
for i=1:60
n=(i-1)*10
i
if i==1
BigPhi(i:(i*10),i:(i*10))=Phi(i,i);
end;
if i>1
BigPhi((i-1)*10:(i*10),(i-1)*10:(i*10))=Phi(i,i);
end
end
I will appreciate any help.

채택된 답변

Image Analyst
Image Analyst 2012년 6월 2일
One line of code:
BigPhi = imresize(Phi, [600 600], 'nearest');
By the way don't do this:
size = 60;
By doing so, you just blew away the very useful built in size() function!!!
  댓글 수: 1
bikekowal Marcin Kowalski
bikekowal Marcin Kowalski 2012년 6월 4일
Oh, Why I didn't see this answer before? This is what I am talking about :) Thanks so much :)

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

추가 답변 (4개)

bikekowal Marcin Kowalski
bikekowal Marcin Kowalski 2012년 6월 2일
OK, I will remeber. Thanks for that.

Ryan
Ryan 2012년 6월 2일
clear m n o p
% Generate matrices
sizeA = 60;
fill_size = 10;
Phi = rand(size,size)>0.5;
BigPhi = zeros(600,600);
% Define BigPhi position counters
o = 1;
p = 1;
%Fill BigPhi
for m = 1:sizeA
for n = 1:sizeA
BigPhi(p:m*fill_size,o:n*fill_size) = repmat(Phi(m,n),[fill_size fill_size]);
p = p + fill_size;
end
o = o + fill_size;
end
I don't have Matlab on this computer to test it, but I believe this should do what you're asking for. The m and n counters keep track of your position in Phi so you can pull out the appropriate data and also dictate the end range of where you will stop filling BigPhi with that value. The o and p counters provide a way to keep track of where to start filling (1,11,21, etc).
B = repmat(A,[m n]) creates a larger m*n matrix, B, by repeating A.
  댓글 수: 1
Ryan
Ryan 2012년 6월 2일
Go with Image Analyst answer. Much quicker than mine.

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


bikekowal Marcin Kowalski
bikekowal Marcin Kowalski 2012년 6월 2일
Thank you for the code, but it doesn't work correctly. There is some mistake
"Subscripted assignment dimension mismatch." in this line:
BigPhi(p:m*fill_size,o:n*fill_size) = repmat(Phi(m,n),[fill_size fill_size]);
  댓글 수: 3
bikekowal Marcin Kowalski
bikekowal Marcin Kowalski 2012년 6월 4일
No, still the same error.
Ryan
Ryan 2012년 6월 4일
I took a quick look at it and fixed the first bug, but ran into another. The skeleton is there if you'd like to debug and figure out where in the algebra it is getting screwed up, but I'd suggest trying what Image Analyst did. I don't have the time to try to fix it.

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


Walter Roberson
Walter Roberson 2012년 6월 4일
I would have to test to be sure this is exactly right, but I believe you can use
BigImage = kron(SmallImage, eye(10));
Be sure to test that this returns the correct class() for your purposes; you might need
BigImage = cast( kron(SmallImage, eye(10)), class(SmallImage) );
  댓글 수: 4
Walter Roberson
Walter Roberson 2012년 6월 4일
That makes sense, andrei.
bikekowal Marcin Kowalski
bikekowal Marcin Kowalski 2012년 6월 5일
Yes, this is it! Thanks a lot guys!

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

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by