From: Ayan on 3 Jun 2010 02:20 Walter Roberson <roberson(a)hushmail.com> wrote in message <AOtNn.21341$7d5.5805(a)newsfe17.iad>... > Ayan wrote: > > > I am looking for some help in dividing an image to 8x8 block and access > > each block separately. My image I is of size 640x480. I need to divide > > the image into subblocks of size 8x8 and have to find histogram of each > > block separately. blkproc is not helping as I cannot access each block > > separately. > > You posted the same question before, but then and now I do not know what > you mean by "access each block separately" ? blkproc() would pass the > provided function the complete matrix that is the current block. Doing a > histogram of a single block would seem to only require the values in the > block. Is there something you have not mentioned that would require the > block coordinates? Hi Walter, I dont thing my problem is very much complex. The only thing is I am very much new to Matlab for which I am facing the problem. I tried to break the main image into subblocks of 8x8 as I need to find the local max of the histogram of each block. But as Jos have mentioned, my image size is not divisible absolutely by 8 (245x133 is my image size) and hence I need to do something to pass the arguments into mat2cell. I am trying to handle this issue. Regards, Ayan
From: Laxminarayana on 2 Jul 2010 04:00 "Ayan " <a.chaki(a)lycos.com> wrote in message <hu7hj5$31d$1(a)fred.mathworks.com>... > Walter Roberson <roberson(a)hushmail.com> wrote in message <AOtNn.21341$7d5.5805(a)newsfe17.iad>... > > Ayan wrote: > > > > > I am looking for some help in dividing an image to 8x8 block and access > > > each block separately. My image I is of size 640x480. I need to divide > > > the image into subblocks of size 8x8 and have to find histogram of each > > > block separately. blkproc is not helping as I cannot access each block > > > separately. > > > > You posted the same question before, but then and now I do not know what > > you mean by "access each block separately" ? blkproc() would pass the > > provided function the complete matrix that is the current block. Doing a > > histogram of a single block would seem to only require the values in the > > block. Is there something you have not mentioned that would require the > > block coordinates? > Hi Walter, > > I dont thing my problem is very much complex. The only thing is I am very much new to Matlab for which I am facing the problem. I tried to break the main image into subblocks of 8x8 as I need to find the local max of the histogram of each block. But as Jos have mentioned, my image size is not divisible absolutely by 8 (245x133 is my image size) and hence I need to do something to pass the arguments into mat2cell. I am trying to handle this issue. > > Regards, > Ayan Hi Ayan, Though my process look lengthy, but it may be helpful to you. As u said that ur image size is 640x480 and u want to divide it into 8x8 blocks (i'm assuming NON OVERLAPPING) try the below code. %//////////////////////////////////////////////////////////////////////// I=imread('imagefile.extension'); [r c]=size(I); bs=8; % Block Size (8x8) nob=(r/bs)*(c/bs); % Total number of 8x8 Blocks % Dividing the image into 8x8 Blocks kk=0; for i=1:(r/bs) for j=1:(c/bs) Block(:,:,kk+j)=I((bs*(i-1)+1:bs*(i-1)+bs),(bs*(j-1)+1:bs*(j-1)+bs)); end kk=kk+(r/bs); end % Accessing individual Blocks figure;imshow(Block(:,:,1)) % This shows u the fist 8x8 Block in a figure window figure;imshow(Block(:,:,2)) % This shows u the second 8x8 Block (i.e as per my %coding rows from 1:8 and col from 9:16) in a figure window and so on..... % Looking at Histograms of Individual Blocks figure;imhist(Block(:,:,1)) % Displays histogram window of first Block figure;imhist(Block(:,:,2)) % Displays histogram window of second Block andso on..... % \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ Hope this will be helpful to You..... ALL THE BEST...
From: Jan Simon on 2 Jul 2010 04:19 Dear Laxminarayana, > I=imread('imagefile.extension'); > [r c]=size(I); > bs=8; % Block Size (8x8) > > nob=(r/bs)*(c/bs); % Total number of 8x8 Blocks Then do not forget to pre-allocate: Block = zeros(r/bs, c/bs, nob); > % Dividing the image into 8x8 Blocks > kk=0; > for i=1:(r/bs) > for j=1:(c/bs) > Block(:,:,kk+j)=I((bs*(i-1)+1:bs*(i-1)+bs),(bs*(j-1)+1:bs*(j-1)+bs)); > end > kk=kk+(r/bs); > end This is equivalent to: Im = imread('imagefile.extension'); [r, c]=size(I); Im = reshape(Im, r/8, 8, c/8, 8); Im = permute(Im, [1, 3, 2, 4]); Im = reshape(Im, 8, 8, []); You can access also matrix sizes, which are not multiple of 8: r8 = 8 * floor(r / 8); c8 = 8 * floor(c / 8); Im = reshape(Im(1:r8, 1:c8), r8/8, 8, c8/8, 8); Now Im(:, :, n) is the n.th block. Good luck, Jan
|
Pages: 1 Prev: s-function within s-function Next: command line rad/s -> Hz in Bode plot |