How to plot pixel intensity as a function of pixel position (beginner)

20 ビュー (過去 30 日間)
Hi I am basically a beginner with imaging processing, I have seen many demos about analyzing the rhinos.avi video but as a beginner I find it a bit complicated. So to start I would like to take a single column of pixels from frame and create an intensity vs position plot.
I would like to know how to select a region of the frame because right now I am just selecting the whole picture.
Thanks in advance!
As of now, I am just getting an empty plot, this is how I am trying to do it: (attached is the frame image)
clear; clc; clf; close all; imtool close all;
myImage = imread('C:\Users\alfre\Downloads\Frame 0001.png')
grayImage = rgb2gray(myImage);
meanGrayLevel = mean2(grayImage);
plot(meanGrayLevel)

採用された回答

Riccardo Scorretti
Riccardo Scorretti 2022 年 4 月 27 日
Hi. You obtain an empty plot because you use mean2, which returns the average of the full image (= a single value):
% Load the image and convert it to BW
clear; clc; clf; close all; imtool close all;
myImage = imread('Frame 0001.png');
grayImage = rgb2gray(myImage);
size(grayImage)
ans = 1×2
334 638
% This will give you the average value of the whole intensity = a single value
meanGrayLevel = mean2(grayImage);
By using mean, you should obtain what you want:
% This will you give the average for each colum = N values, which can be plotted
meanGrayLevel = mean(grayImage, 1);
% Plot the image together with the average intensity on each column
subplot(2, 1, 1) ; imagesc(grayImage) ; colormap gray
subplot(2, 1, 2) ; plot(meanGrayLevel) ; axis([1 size(grayImage,2) -inf inf]);
Finally, you can get a portion of the image by using the usual synpsis for matrix:
% Take a subset of the image
rhino = grayImage(100:250, 200:300);
figure
imagesc(rhino) ; colormap gray ; axis image
  1 件のコメント
Alfredo Scigliani
Alfredo Scigliani 2022 年 4 月 27 日
This is exactly what I was looking for, thanks!!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeModify Image Colors についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by