How to divide gray scale image into 8x8 blocks and access each block separately to apply dct2 on the block

12 ビュー (過去 30 日間)
I want to divide the grayscale image which in my case is the 'cameraman.tif' into 8x8 blocks then run dct2 on each block to
later hide a binary watermark image into each block.
So far I tried blockproc and many other methods but none of them satisfy my needs.
  2 件のコメント
dharaneesh govindaraj
dharaneesh govindaraj 2021 年 10 月 23 日
I want to do same process. I dont know how to convert the image and watermark. Please help me by providing code
Image Analyst
Image Analyst 2021 年 10 月 23 日
編集済み: Image Analyst 2021 年 10 月 23 日
@dharaneesh govindaraj, start with running and understanding my attached blockproc() demos. Then adapt them to make the function it runs fft2() instead of whatever I used. But this is essentially what Stephane does below.

サインインしてコメントする。

採用された回答

Stephane Dauvillier
Stephane Dauvillier 2019 年 4 月 29 日
編集済み: Stephane Dauvillier 2019 年 4 月 29 日
file = 'cameraman.tif';
im=imread(file);
imshow(im);
In order to use blockproc you have to use a function that accpts blocksstructure, that's why you need to use something like this
imModified = blockproc(im,[8 8],@(blkStruct) dct2(blkStruct.data));
imshow(imModified)
I hope this answers your question
  2 件のコメント
Ari M Salih
Ari M Salih 2019 年 4 月 29 日
But how do I access each block to add the watermarked image to it?
This works but I still need to access them
Stephane Dauvillier
Stephane Dauvillier 2019 年 4 月 29 日
You have a function to add your watermak ?
Let's just say you have your function has followed
function imageWithWatermak = myFunction(imageWithoutWatermark)
...
end
Then you will do
blockproc(im,[8 8],@(blkStruct) myFunction(blkStruct.data));

サインインしてコメントする。

その他の回答 (1 件)

KALYAN ACHARJYA
KALYAN ACHARJYA 2019 年 4 月 29 日
編集済み: KALYAN ACHARJYA 2019 年 4 月 29 日
image1=rgb2gray(imread('test.jpg'));
[rows colm]=size(image1);
% pading for make 8 disible, im my case rows 96 and colm 200
% 96 alread divisible by 8, no need modification: 12
% colm 200 no need modification: 25
% Otherwise do zero pading, where required rows or colm, or both
result=dct2(image1,[12 25]);
% This size [12 25] divides the image in 8x8 blocks, each block size is 12x25
imshow(result);
77.png
There may more simpler way also.

カテゴリ

Help Center および File ExchangeImage Processing Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by