How do you create a test image containing a ramp edge?

조회 수: 9(최근 30일)
Prashant
Prashant 2022년 12월 2일
편집: DGM 2022년 12월 3일
This is the ideal solution
this is my solution with the following (amateur approach) code:
I = uint8(zeros(40,150));
I(:,100:150) = 128;
X2=uint8(0:49);
X3=uint8(50:99);
Y=uint8(0:39);
I(:,50:99)=meshgrid(X2,Y);
I(:,100:149)=meshgrid(X3,Y);
figure, imshow(I), title("ramp edge")

채택된 답변

DGM
DGM 2022년 12월 2일
편집: DGM 2022년 12월 3일
Here's one way.
outpict = zeros(1,150,'uint8'); % a blank vector
outpict(50:99) = linspace(0,128,50); % add a linear ramp in the middle
outpict(100:end) = 128; % fill the end
outpict = repmat(outpict,[40 1]); % replicate it
imshow(outpict)
Here's a different way:
outpict = linspace(0,150*128/50,150); % a 1D linear ramp at the appropriate slope
outpict = min(outpict-49*128/50,128); % truncate it
outpict = uint8(repmat(outpict,[40 1])); % replicate it
imshow(outpict)
Or if you're using MIMT, you can just do
outpict = lingrad([40 150],[0 1/3; 0 2/3],[0; 128],'linear','uint8');
imshow(outpict)
... which is generally more flexible.
See also:

추가 답변(0개)

범주

Find more on Linear Algebra in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by