フィルターのクリア

Extract specific row from an image and average with a variable number of adjacent rows

2 ビュー (過去 30 日間)
Hello.
I have an image that I perfrom a "linescan" at a specific row at 'xcol'
I want to create a "thick" linescan so include the adjacent rows and then average. Below I have done it for a total of 5 rows (including the centre one).
yth_row=(img(xcol,:)+img(xcol-1,:)+img(xcol+1,:)+img(xcol-2,:)+img(xcol+2,:))/5;Extract
Can this be simplified to any (odd) number of rows to include?

採用された回答

Constantino Carlos Reyes-Aldasoro
Constantino Carlos Reyes-Aldasoro 2019 年 12 月 3 日
Certainly it can be done much easier. Instead of this
yth_row=(img(xcol,:)+img(xcol-1,:)+img(xcol+1,:)+img(xcol-2,:)+img(xcol+2,:))/5;
try this
yth_rows =(img(xcol-2:xcol+2,:); % this will select from 2 rows before to 2 after, so it is a matrix not a row
yth_row = mean(yth_rows); % obtain the average.
This has the advantage that you could even do it for n and the mean will work no matter how many lines you average, you could even do it in a single line, I did it in two to illustrate above, but this works as well
n = 2; % number of lines above and below to consider
yth_rows =mean(img(xcol-n:xcol+n,:)); % select from n rows above and below average.
Hope that answers the question.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeImage Processing Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by