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

7 views (last 30 days)
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")

Accepted Answer

DGM
DGM on 2 Dec 2022
Edited: DGM on 3 Dec 2022
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:

More Answers (0)

Categories

Find more on Introduction to Installation and Licensing in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!