How to store the difference between adjacent pixel values of image

조회 수: 6 (최근 30일)
layth ibrahim
layth ibrahim 2022년 4월 11일
댓글: layth ibrahim 2022년 4월 15일
I have a black and white image and I need to store the value of the differences between each adjacent pixel so that i may plot the values in a histogram.
  댓글 수: 3
layth ibrahim
layth ibrahim 2022년 4월 11일
Starting from pixel (1,1) after that the difference with the pixel before its position. Sorry, I should have said its grayscale.
layth ibrahim
layth ibrahim 2022년 4월 15일
Was recently told I need to use a nested "for" loop to acomplish the task.

댓글을 달려면 로그인하십시오.

답변 (2개)

Benjamin Thompson
Benjamin Thompson 2022년 4월 11일
편집: Benjamin Thompson 2022년 4월 11일
Use imfilter with a 1D filter argument. If your h is vertical then the difference operation is in the vertical direction. If the filter coefficients h are horizontal then the difference operation is horizontal.
>> imshow(phantom)
>> imshow(imfilter(phantom, [-1 1]))
>> imshow(imfilter(phantom, [-1 1]'))

DGM
DGM 2022년 4월 11일
If all you want is the difference in one direction, then just use diff().
A = randi([0 255],10);
dAdx = diff(A,1,2);
histogram(dAdx(:))

카테고리

Help CenterFile Exchange에서 Image Filtering and Enhancement에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by