Extracting center most submatrix from kspace

3 次查看(过去 30 天)
I have an image of [256,256]
I want the center most submatrix of [32,32] and equate the rest of kspace to zero
  1 个评论
Walter Roberson
Walter Roberson 2021-9-11
You flagged your own Question as being a Duplicate, but you have only posted this Question, so it is not clear what it is a duplicate of ?

请先登录,再进行评论。

采纳的回答

Image Analyst
Image Analyst 2020-2-9
Pretty easy. Just get the coordinate of the cluster centroid, then use sort() to get the 32 points closest to the centroid. Is this homework (sounds like it)? Here's a start
% [idx,C,sumd,D] = kmeans(___) returns distances from each point to every centroid in the n-by-k matrix D.
meanCoords = mean(X, 2) % X is N rows (one for each point) by k columns (one for each dimension).
distances = sqrt((X(:, 1) - meanCoords(1)).^ 2 + .........one for each k) you can use a for loop if k is variable/unknown.
[sortedDistances, sortOrder] = sort(distances, 'ascend');
closest32Indexes = sortOrder(1:32)
x32 = X(closest32Indexes, :);

更多回答(1 个)

Walter Roberson
Walter Roberson 2021-9-11
YourImage = imread('cameraman.tif');
subsize = [32, 32];
[r, c, p] = size(YourImage);
start_r = floor((r-subsize(1))/2);
start_c = floor((c-subsize(2))/2);
kspace = zeros(size(YourImage), 'like', YourImage);
kspace(start_r:start_r+subsize(1)-1, start_c:start_c+subsize(2)-1,:) = YourImage(start_r:start_r+subsize(1)-1, start_c:start_c+subsize(2)-1,:);
imshow(YourImage)
imshow(kspace)

类别

Help CenterFile Exchange 中查找有关 Automotive 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by