フィルターのクリア

How to delete every second pixel of each row from a photo?

5 ビュー (過去 30 日間)
Ferdows Dolon
Ferdows Dolon 2014 年 9 月 13 日
コメント済み: Image Analyst 2014 年 9 月 13 日
Hi everyone,
I need to write a program which will take a photo as a input and then I want to delete every second pixel of each row from a photo.
How can i do this? Thank you very much.
regards
ferdows

採用された回答

Image Analyst
Image Analyst 2014 年 9 月 13 日
Try this for a gray scale image:
grayImage= grayImage(:, 1:2:end);
Or, if it's an RGB image:
rgbImage = rgbImage(:, 1:2:end, :);
You can assign it to a different image if you don't want to change your input image.
grayImage2 = grayImage(:, 1:2:end);
rgbImage2 = rgbImage(:, 1:2:end, :);
You can also start at column 2 if you want but using 2:2:end instead of 1:2:end.
  1 件のコメント
Image Analyst
Image Analyst 2014 年 9 月 13 日
It's really easy to just do in a single line like I suggested above, but if really you need it as a function....
function outputImage = SubSampleImage(inputImage)
[rows, columns, numberOfColorChannels] = size(inputImage);
if numberOfColorChannels == 1
outputImage = inputImage(:, 1:2:end);
else
outputImage = inputImage(:, 1:2:end, :);
end
though when you call this function you'll still have a single line of code like you'd have if you used my first suggestion and didn't use a function, because you need to call the function. My function is robust enough to handle both gray scale and multispectral/RGB images.

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

その他の回答 (2 件)

Rushikesh Tade
Rushikesh Tade 2014 年 9 月 13 日
編集済み: Rushikesh Tade 2014 年 9 月 13 日
Try following code:
function output_image=alternate_rows(input_image)
output_image=[];
for i=1:size(input_image,1)
output_image=[output_image input_image(i,1:2:size(input_image,2))]
end

Adam
Adam 2014 年 9 月 13 日
nCols = size( photo, 2 );
photo = photo( :, 1:2:nCols );

カテゴリ

Help Center および File ExchangeImage Segmentation and Analysis についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by