I take 4x4 blocks from the Gray image , filtered it and now i want to return it back to the original gray .

2 views (last 30 days)
Dear all ;
I have a gray image . I convert it to DCT . Then i take 4x4 blocks from this DCT of the gray image . I convert the 4x4 dct blocks to idct . Then i filter this 4x4 .
Now i want to take the filtered 4x4 and put it to the original gray image . How ?!
The code is the following :
% Convert to DCT: gray3=dct2(gray2); gray4=gray3(1:4,1:4);
% Convert to idct : IDCT_Gray=idct2(gray4);
%then i filter IDCT_Gray.
Assume the filter output is yy2 . How can i return this 4x4 filter output to the original gray image .
thank you

Accepted Answer

sixwwwwww
sixwwwwww on 24 Oct 2013
Dear Zgrt, you can do it the following way:
gray3=dct2(gray2);
gray4=gray3(1:4,1:4);
IDCT_Gray=idct2(gray4);
h = fspecial('motion'); % Its a sample filter, you can choose according to your need
yy2 = imfilter(IDCT_Gray, h); % Applying the filter to extracted part
gray2(1:4, 1:4) = uint8(yy2); % Putting the back the precessed extracted part into the gray image
I hope it helps. Good luck!
  3 Comments
zgrt
zgrt on 24 Oct 2013
This is the code : gray2(1:4,1:4)=uint8(yy2); graynew=gray2; graynew2=uint8(graynew); figure(1) imshow(graynew2);
but the filtered 4x4 once i return it back to the gray2 ( original gray image) it becomes an empty square block
sixwwwwww
sixwwwwww on 24 Oct 2013
Basically the problem in this technique is that in your gray image you have values in uint8 data type and when you convert it DCT you get values in double data type. The values in uint8 range from 0-255. See http://www.mathworks.com/help/matlab/ref/intmax.html
however in double data type values range from about 10^+308. See http://www.mathworks.com/help/matlab/ref/realmax.html. So when you perform filtering on double double data type they remain double data type and values are typically very large. So when you convert these values back to unit8 type then values are fixed to maximum value of uint8 which is 255. That's the reason that you don't see anything interesting

Sign in to comment.

More Answers (2)

zgrt
zgrt on 25 Oct 2013
I got your answer . Thank you . So is their any other solutions to solve this problem or i have to change my idea .
  3 Comments
sixwwwwww
sixwwwwww on 25 Oct 2013
I will suggest that you do processing in one of two domains. I mean perform all operations in RGB domain or do all the processing in DCT domain. Then it will be easy to handle

Sign in to comment.


Image Analyst
Image Analyst on 27 Oct 2013
Sounds like you have it solved since you marked this as accepted but I didn't understand it. I don't know anything about compression (if that's what you're doing) but your explanation of the algorithm, which makes no sense to me. You say you convert an image to DCT, then you take 4x4 blocks. yet your code only deals with the first block, not all of them. Then you inverse transform it, which will of course not give you the same size image in the spatial domain that you started with, but a 4x4 spatial domain image. Perhaps you wanted to zero out the other blocks, maintaining the same size spectrum, rather than extracting 14 elements from it.
But anyway, you then have a very, very tiny, very, very blurry spatial domain image again. But now you say you want to filter it . Strange, because you were just in the Fourier domain and already filtered it there (by taking just a 4x4 chunk of it) so why filter it again in the spatial domain??? And exactly what type of spatial domain filtering can you have with only 4 by 4 pixels? Nothing of any use, I would think.
But whatever....at least you have it solved (whatever it is).

Community Treasure Hunt

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

Start Hunting!