MATLAB Answers

How do I make a 21x21 array from the center of a 200x150 array?

3 ビュー (過去 30 日間)
Andrew Trammell
Andrew Trammell 2019 年 10 月 14 日
編集済み: Star Strider 2019 年 10 月 14 日
grayscale.png
This image is 200x150. How do I create a 21x21 array from the center of the 200x150 array?

  0 件のコメント

Sign in to comment.

回答 (2 件)

Star Strider
Star Strider 2019 年 10 月 14 日
編集済み: Star Strider 2019 年 10 月 14 日
I called your image ‘parrot grayscale.png’.
I = imread('parrot grayscale.png');
[r,c] = size(I);
sr = fix((r-21)/2);
sc = fix((c-21)/2);
I2121 = I(sr:sr+20, sc:sc+20);
figure
imshow(I2121)
EDIT — Corrected typographical error. Code otherwise unchanged.

  0 件のコメント

Sign in to comment.


Fabio Freschi
Fabio Freschi 2019 年 10 月 14 日
% dimensions
n = 21; % rows
m = 21; % cols
% load image
A = imread('grayscale.png');
% find center coordinate
iCenter = round(size(A)/2);
% indices to save
iRow = iCenter(1)-floor(n/2)+(1:n);
jCol = iCenter(2)-floor(m/2)+(1:m);
% extraction
B = A(iRow,jCol);
% plot
figure
imshow(B)

  0 件のコメント

Sign in to comment.


Translated by