Number of dark stripe in a image

How can I calculate number of black or gray stripe in the above region using Matlab (not by counting then manually)?

回答 (1 件)

Nathan Hardenberg
Nathan Hardenberg 2023 年 5 月 23 日

2 投票

I would extract one line of pixels in the image and then use the islocalmin() or islocalmax()-function. This searches for local minima/maxima. Depending on counting black or white stripes (to count black you need islocalmin()).
Then you just need to check the length of the vector.
If you have Problems (e.g. finding multiple maxima/minima in one stripe) check the documentation for possible arguments which could resolve possible issures.
Note that this only works if your stripes are always "clean". If not possible filtering beforehand might be nessescary.

5 件のコメント

Amrit Kumar Mondal
Amrit Kumar Mondal 2023 年 5 月 24 日
Dear Hardenberg,
Thank you for your suggestion.
Can you please help me, How to take line scan along x direction?
Nathan Hardenberg
Nathan Hardenberg 2023 年 5 月 24 日
Here is some example code, that works if the image has no noise:
imageRGB = imread(".\myfolder\1.png");
imageGray = rgb2gray(imageRGB); % convert to grayscale (if necessary)
n = 2 % Linenumber to analyse
line = imageGray(n, :)
minima = islocalmin(line)
nrOfBlackLines = sum(minima)
Amrit Kumar Mondal
Amrit Kumar Mondal 2023 年 5 月 24 日
Thank you for your help.
I am using Matlab R2017a and I have attached one error for the code. Here, islocalmin() command is not working.
Nathan Hardenberg
Nathan Hardenberg 2023 年 5 月 24 日
You could use the findpeaks()-function and negate your signal to find the minimas
minima = findpeaks(-single(line))
Amrit Kumar Mondal
Amrit Kumar Mondal 2023 年 5 月 25 日
Thank you Hardenberg.

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

カテゴリ

ヘルプ センター および File ExchangeIntroduction to Installation and Licensing についてさらに検索

質問済み:

2023 年 5 月 23 日

コメント済み:

2023 年 5 月 25 日

Community Treasure Hunt

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

Start Hunting!

Translated by