24小时热门版块排行榜    

Znn3bq.jpeg
北京石油化工学院2026年研究生招生接收调剂公告
查看: 1401  |  回复: 8
当前只显示满足指定条件的回帖,点击这里查看本话题的所有回帖

xmcrobbie

银虫 (小有名气)

[求助] 有段程序,就5,6行,我看了N天了,请教高手

function Y = sampleWithR(weights,K)
%Y = sampleWithR(weights,K)
%Generates K samples from the discrete distribution specified by weights
%O(K)

%Need to handle border effects
cdf = cumsum(weights);
Y = histc(rand(K,1)*cdf(end),[0; cdf]);
Y = [Y(1:end-2); Y(end-1)+Y(end)];


我不知道这个函数起什么作用啊。。。。
回复此楼

» 猜你喜欢

» 本主题相关价值贴推荐,对您同样有帮助:

已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

xmcrobbie

银虫 (小有名气)

引用回帖:
7楼: Originally posted by coolslj at 2013-10-22 12:50:06
楼主没有提供该程序的背景和上下文,所以专家们有点盲人摸象。

该程序根据一个分布的直方图,产生了一个新的分布的直方图。
从这个角度看,该程序无实际意义。
我推测它主要是用于教学。...

function res = searchImCostTRandEndc (im,len,wid,MAX_NUM,thresh,currAngles)
%[res,respOut] = getSegments (im,frameNum,len,wid,thresh,currAngles)
%Searches binary im for patches of size len by wid of white
%Randomized version, thresh is the number of examples to return

SUPPRESS = 0;
SCALE = 1/3; %When we weight the background flanks by .5
%SCALE = 1/2;

%We want our final log potentials to be between 0 & 10
%FINAL_SCALE = 1/3;

[origY, origX, dummy] = size(im);


if ~exist('currAngles'),
  currAngles = 15:15:360;
  %currAngles = 15:15:180;
end
if ~exist('roi'),
  roi = [1 1;origY origX];
end

%Thresh is the number of pixels we're allowing to be misclassified
if ~exist('thresh') | isempty(thresh),
    %thresh = 1*len*wid;
    thresh = 0;
end

%Convert to a probability
%thresh = exp(-thresh/SCALE);

%Add the size of our patch to buffer our ROI
roi = round(roi + max([len wid])*[-1 -1;1 1]);

%Make sure ROI does not exceed our image dimensions
roi(1, = max([1 1],roi(1,);
roi(2, = min([origY origX],roi(2,);

%dtheta = 15;
ddir = 1; %Maybe go back to 2?
ddir = min(length(currAngles)-1,ddir);
dpos = 1; %Maybe go back to 2?

im = im(roi(1,1):roi(2,1),roi(1,2):roi(2,2),;
[imy,imx,dummy] = size(im);

%Shift our currentAngle
currAngles = -90 - currAngles;

[len,wid] = deal(round(len),round(wid));

%im = uint8(im);
%wwid = ceil(wid/8);
%wwid = 2;

%imPatch = [zeros(len,wid) ones(len,wid) zeros(len,wid)];
%Use felzenswchab style likelihood
%imPatch = [zeros(wid,wid*3); -ones(len,wid) ones(len,wid) -ones(len,wid); -ones(wid,wid*3)];

yy = [-(len-1)/2len-1)/2].^2/(.4*len.^2);
xx = [-(wid-1)/2wid-1)/2].^2/(.4*wid.^2);
[yy,xx] = ndgrid(yy,xx);
kk = exp(-(yy + xx));
kk = kk.*(len*wid/(sum(kk()));
imPatch = [zeros(wid,wid*3); -ones(len,wid) kk -ones(len,wid); -ones(wid,wid*3)];

%yind = 1:len; yind = yind - mean(yind);
%xind = 1:wid; xind = xind - mean(xind);
%[Y,X] = ndgrid(yind/(5*len),xind/(5*wid));
%imPatch = exp(-Y.^2 + -X.^2);

resp = zeros([length(currAngles) imy imx]);
for dir = 1:length(currAngles),
  currAngle = -90 - currAngles(dir);
  kernal = imrotate(imPatch,currAngle);

  %kernal = kernal./sum(kernal();  
  %kernal = kernal./sum(kernal(kernal > 0));

  [mm,nn,dummy] = size(kernal);
  
  %currResp = filter2(kernal == 1,im == 0,'valid') + .5*filter2(kernal == 0,im == 1,'valid');
  %tmp = filter2(kernal == 1,im == 0,'valid');
  tmp = filter2(kernal.*(kernal > 0),im == 0,'valid');
  currResp = tmp + .25*filter2(kernal < 0,im == 1,'valid');
  indy = ceil(mm/2):imy-floor(mm/2);
  indx = ceil(nn/2):imx-floor(nn/2);
  if ~isempty(currResp),
    %resp(dir,indy,indx) = exp(-currResp/SCALE);  
    %currResp = exp(-currResp/SCALE);
    currResp = exp(-currResp/(len*wid*SCALE));
    %currResp(tmp == sum(kernal( == 1)) = 0;
    currResp(tmp == sum(kernal(kernal > 0))) = 0;
    resp(dir,indy,indx) = currResp;
  end
end

%keyboard;
resp(resp < thresh) = 0;
%ord = find(sampleWithR(exp(-resp(/(len*wid)),thresh));

%%%%%%%%%%%%在这里调用了sampleWithR%%%%%%%
ord = find(sampleWithR(resp(,MAX_NUM));
resp = resp(ord);
[resp,I] = sort(resp);
resp = flipud(resp);
ord = ord(flipud(I));
%ord = ord(I);

res.resp = resp;
%res.resp = resp.^(1/FINAL_SCALE);

[ang i j] = ndgrid(pi/180*currAngles,roi(1,1):roi(2,1), roi(1,2):roi(2,2));

res.resp = resp;
ang = ang(ord); res.u = cos(ang); res.v = sin(ang);
res.x = j(ord);
res.y = i(ord);
res.len = len/2*ones(size(resp));
res.w = wid/2*ones(size(resp));
8楼2013-10-22 14:30:50
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
查看全部 9 个回答

haier20022

新虫 (正式写手)

【答案】应助回帖

感谢参与,应助指数 +1
是matlab程序吧?
2楼2013-10-20 13:33:29
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

feixiaolin

荣誉版主 (文坛精英)

优秀版主

function Y = sampleWithR(weights,K)
% 依权值重采样;
cdf = cumsum(weights);
% 权值累加
Y = histc(rand(K,1)*cdf(end),[0; cdf]);
% 统计直方图
Y = [Y(1:end-2); Y(end-1)+Y(end)];
% 直方图最末一bin修正
3楼2013-10-20 14:40:26
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

xmcrobbie

银虫 (小有名气)

引用回帖:
3楼: Originally posted by feixiaolin at 2013-10-20 14:40:26
function Y = sampleWithR(weights,K)
% 依权值重采样;
cdf = cumsum(weights);
% 权值累加
Y = histc(rand(K,1)*cdf(end),);
% 统计直方图
Y = ;
% 直方图最末一bin修正...

Y = histc(rand(K,1)*cdf(end),[0; cdf]);  这行不理解啊。rand(K,1)是随机产生K个0到1的数吧。[0; cdf] 应该是在在cdf2前加个0吧。

应该是看看产生的这K个数,落在统计直方图中各个bin的个数吧。。。

这么理解对吗?
4楼2013-10-20 16:30:32
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 085600材料与化工专硕329 求调剂 +20 额cc 2026-04-06 21/1050 2026-04-08 16:24 by luoyongfeng
[考研] 0703调剂,一志愿天津大学319分 +23 haaaabcd 2026-04-05 26/1300 2026-04-08 16:19 by luoyongfeng
[考研] 一志愿南昌大学,085600,344分求调剂 +11 调剂上岸玘 2026-04-05 12/600 2026-04-08 16:17 by luoyongfeng
[考研] 化学308分求调剂 +18 你好明天你好 2026-04-07 20/1000 2026-04-08 14:51 by screening
[考研] 293调剂 +18 yj1221 2026-04-08 19/950 2026-04-08 14:33 by 418490947
[考研] 电子信息270求调剂 +7 terminal469 2026-04-07 7/350 2026-04-08 08:48 by tt19890111
[考研] 生物医药调剂|SCI中科院三区一作+多项科研成果 +8 likangxing 2026-04-07 11/550 2026-04-08 00:02 by lys0704
[考研] 材料调剂 +13 汉123456 2026-04-07 14/700 2026-04-07 22:53 by 来看流星雨10
[考研] 081200-11408-276学硕求调剂 +5 崔wj 2026-04-05 5/250 2026-04-06 15:40 by lin-da
[考研] 331求调剂 +8 于征yz 2026-04-05 8/400 2026-04-06 00:54 by fmesaito
[考研] 材料调剂 +6 一样YWY 2026-04-05 6/300 2026-04-05 20:30 by 南航~万老师
[考研] 材料调剂 +12 一样YWY 2026-04-04 12/600 2026-04-05 08:24 by 544594351
[考研] 085602调剂 初试总分335 +12 19123253302 2026-04-04 12/600 2026-04-05 08:08 by 544594351
[考研] 怎么删帖子啊 +3 缝曦1000 2026-04-04 3/150 2026-04-04 14:20 by 土木硕士招生
[考研] 280求调剂 +21 咕噜晓晓 2026-04-02 22/1100 2026-04-04 11:12 by 猪会飞
[考研] 化工求调剂 +11 荔香芝士椰奶 2026-04-03 11/550 2026-04-03 22:06 by 啵啵啵0119
[考研] 286求调剂 +8 lim0922 2026-04-02 8/400 2026-04-03 20:19 by rzh123456
[考研] 274求调剂 +9 顺理成张 2026-04-03 10/500 2026-04-03 15:10 by 啊俊!
[考研] 285求调剂 +7 AZMK 2026-04-02 9/450 2026-04-03 11:12 by wanwan00
[考研] 材料340分调剂 +7 夏夜晚风_long 2026-04-02 9/450 2026-04-02 21:20 by dongzh2009
信息提示
请填处理意见