필터 지우기
필터 지우기

converting 3D matrix to 2D image

조회 수: 4 (최근 30일)
kush
kush 2012년 3월 25일
how to convert 3D matrix C(4x4x64) into 2D W1(32x32) plz help i have divided an image into 4x4 blocks & saved them into matrix C1(a,b,c) now i want to reconvert it into image

답변 (3개)

Image Analyst
Image Analyst 2012년 3월 25일
We have no idea how you want these blocks to be arranged. Please read your message from our point of view and try to figure out what you meant. I don't know what a "block" is - is it a cell? A slice out of a 3D image like C? Is C the original matrix, or the one you have after dividing your image into blocks? You could have 8 4x4 blocks in each direction to get 32 pixels along a dimension, or 64 blocks to make up a 32x32 2D image. Am I supposed to know how all those 64 blocks are to be arranged? In what order?
  댓글 수: 1
kush
kush 2012년 3월 26일
sir,i have divided original image I (32x32) into an array of blocks/cells each of 4x4 size by
[a b] = size(HL31);
c=4;d=4; % reshape it into 4*4 matrices
l=1;
for i=1:c:a-3
for j=1:d:b-3
C1(:,:,l)=HL31((i:i+3),(j:j+3));
C1(:,:,l)=dct2(C1(:,:,l));
l=l+1;
end
end
then i have performed idct on each block
for i=1:size(C1,3)
C5(:,:,i)=idct2(C1(:,:,i));
end
now i want to convert C5 back to a 32x32 image
can u plz help

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


Andrei Bobrov
Andrei Bobrov 2012년 3월 26일
f = @(block_struct)dct2(block_struct.data);
f2 = @(block_struct)idct2(block_struct.data);
C1 = blockproc(HL31,[4 4],f);
C5 = blockproc(C1,[4 4],f2);
OR
ij = {4*ones(size(HL31,1)/4,1),4*ones(size(HL31,2)/4,1)}
C1 = cell2mat(cellfun(@(x)dct2(x),mat2cell(HL31,ij{:}),'un',0))
C5 = cell2mat(cellfun(@(x)idct2(x),mat2cell(C1,ij{:}),'un',0))
OR in your case
s3 = size(C5);
s2 = s3(1:2)*s3(3)/2;
ji = arrayfun(@(x)1:s3(x):s2(x)-s3(x)+1,1:2,'un',0);
[j1,i1] = ndgrid(ji{:});
ii = 0:s3(1)-1;
jj = 0:s3(2)-1;
out = zeros(s2);
for k = 1:numel(j1)
out(i1(k) + ii,j1(k) + jj) = C5(:,:,k);
end
  댓글 수: 2
kush
kush 2012년 3월 26일
thank u
Oleg Komarov
Oleg Komarov 2012년 3월 26일
Please accept his answer if you think it solved your problem.

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


Sandip
Sandip 2013년 8월 8일
I guess I have a similar problem. I have an image (tiff). I want histogram of this image/grey scale. However, when I read in the image, I find that my image (tiff) is in 3 D matrix form. How can I convert the image to 2D matrix! imhist command works only for images with 2D matrix form.
Regards,
  댓글 수: 1
Jan
Jan 2013년 8월 8일
Please post a new question in a new thread. If you highjack an existing thread, it is not clear, which answer belongs to which question, and you cannot selected an accepted answer.

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

카테고리

Help CenterFile Exchange에서 Computer Vision with Simulink에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by