manipulate pixels in an image

Is there a way to include the neighboring pixels into a pixel - in other ways, to include 9 pixels into 1? I dont want to just zoom out, rather I need to adjust the pixel values accordingly and to decrease the amount of total pixels. Thanks in advance.

回答 (4 件)

Image Analyst
Image Analyst 2011 年 6 月 7 日

1 投票

How about
smallerImage = largerImage(1:3:end, 1:3:end) % Subsamples
or to average instead of subsample:
smallerImage = conv2(single(largerImage), ones(3)/9, 'same'); % To average, but same size.
smallerImage = smallerImage (1:3:end, 1:3:end) % Then subsamples to resize.
You might want to cast smallerImage to uint8 if you want to display it with imshow().
Bjorn Gustavsson
Bjorn Gustavsson 2011 年 6 月 7 日

1 投票

Something like this will do it:
img_in = randn(36);
M = eye(size(img_in,1)/3);
idx = sort(repmat(1:size(M,1),3,1));
M = M(:,idx);
img_out = M*(M*img_in')'/9;
Obviously I haven't bothered comparing this with a straightforward looped algorithm, but this doesn't scale well att all with size...
...something like O(n^3) when I guess a looped should scale with O(n^2).
Titus Edelhofer
Titus Edelhofer 2011 年 6 月 7 日

0 投票

Hi,
if you have the image processing toolbox, you can use the function imresize.
Titus

1 件のコメント

J J
J J 2011 年 6 月 7 日
thx Titus; and if I dont (which is the case)? Is there a way to manually do it? a for loop is not preferred since there are many many pixels.

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

Jonas Reber
Jonas Reber 2011 年 6 月 7 日

0 投票

if you don't have it you could take a look at e.g. http://www.mathworks.com/matlabcentral/fileexchange/4658-updownsample

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

質問済み:

J J
2011 年 6 月 7 日

Community Treasure Hunt

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

Start Hunting!

Translated by