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

조회 수: 63 (최근 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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by