
How to add noise to rect fuction (rectangle) ?
1 回表示 (過去 30 日間)
古いコメントを表示
How to add noise to the edges of 2D rect function? While all the rest is 1 and 0. So that the lines are not straight but still have value of 1.
x = linspace(1,10,100);
y = x;
[X Y] = meshgrid(x,y);
T = rect(X/2).*rect(Y/2);
function A = rect(x)
% rectangle function
A = abs(x) <=1/2;
end
how to add noise to line edges (borders) of T only?
0 件のコメント
回答 (2 件)
Image Analyst
2014 年 11 月 21 日
Try this:
clc;
clearvars;
close all;
workspace;
verticalElements = 100;
horizontalElements = 150;
x1 = 4;
y1 = 2;
x2 = 12;
y2 = 8;
% Make x values.
xTop = linspace(x1,x2,horizontalElements);
xBottom = fliplr(xTop);
xLeft = x1+rand(1,verticalElements) - 0.5;
xRight = x2+rand(1,verticalElements) - 0.5;
% Make y values.
yLeft = linspace(y1, y2,verticalElements);
yRight = linspace(y2, y1,verticalElements);
yTop = 8 + rand(1, horizontalElements) - 0.5;
yBottom = 2 + rand(1, horizontalElements) - 0.5;
% Make a box with jagged edges
xBox = [xTop, xRight, xBottom, xLeft];
yBox = [yTop, yRight, yBottom, yLeft];
% Close it
xBox(end+1) = xBox(1);
yBox(end+1) = yBox(1);
% Plot it.
plot(xBox, yBox, 'LineWidth', 2);
grid on;

0 件のコメント
Youssef Khmou
2014 年 11 月 20 日
The solution exists for one dimensional function, when you apply the function, you obtain a logical array, you need to convert it to double and find non zero indexes :
rec=@(x) abs(x)<=1/2;
f=rec(-2:0.01:2);
[a,b]=find(f~=0);
N=length(b);
s=0.15;% noise power
f=double(f);
f(b)=1+s*randn(1,N);
plot(f);

参考
カテゴリ
Help Center および File Exchange で NaNs についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!