フィルターのクリア

convert larger image into patches

4 ビュー (過去 30 日間)
cameron lord
cameron lord 2020 年 12 月 1 日
コメント済み: Image Analyst 2020 年 12 月 2 日
hi there,
I currently have a large image sized 600x1000 and would like to instead read this as patches of 51x51, how can I do this?
have tried to reshape but number of elements in each doesn't match to an integer
thanks very much

回答 (2 件)

Ameer Hamza
Ameer Hamza 2020 年 12 月 1 日
img = rand(600,1000);
img_parts = mat2tiles(img, [51 51])
  2 件のコメント
cameron lord
cameron lord 2020 年 12 月 1 日
Thankyou, I used mat2tiles and it splits the image up - but i am trying to multiply each of the patches with a 51x51 filter matrix but cannot as my original image is not a multiple of 51 so some of the matrix dimensions disagree.
is there a way to get round this?
Ameer Hamza
Ameer Hamza 2020 年 12 月 2 日
You can remove those cells
img = rand(600,1000);
img_parts = mat2tiles(img, [51 51]);
idx = ~cellfun(@(x) all(size(x)==[51 51]), img_parts);
img_parts(:,all(idx,1)) = [];
img_parts(all(idx,2),:) = [];

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


Image Analyst
Image Analyst 2020 年 12 月 1 日
What exactly do you mean by "read this"? Do you want to resize the entire image to 51x51 with imresize(yourImage, [51, 51]) or do you want to scan the image with a 51x51 window, moving in jumps of 51 pixels, and process the image inside, like you'd do with blockproc(). I'm attaching images for blockproc.
If the image is not a perfect multiple of 51, what do you want to do with the left over sliver?
  2 件のコメント
cameron lord
cameron lord 2020 年 12 月 1 日
yes, your right with the second one. i'd like to process the whole image - but in chunks of 51x51, passing them through a filter then plot the resulting activation map.
as for the sliver that will be left over, i'm not entirely sure. perhaps just remove it from the activation map completely?
Image Analyst
Image Analyst 2020 年 12 月 2 日
OK, so simply crop the image before blockproc() with indexing. Just compute the number of blocks.
numBlocksR = size(yourImage, 1);
numBlocksC = size(yourImage, 2);
yourImage = yourImage(1 : (floor(numBlocksR/51) * 51), 1 : (floor(numBlocksC/51) * 51), :);

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

Community Treasure Hunt

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

Start Hunting!

Translated by