| 9 | 1/1 | 返回列表 |
| 查看: 1369 | 回復(fù): 8 | |||
[求助]
有段程序,就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)]; 我不知道這個函數(shù)起什么作用啊。。。。 |
新蟲 (正式寫手)
榮譽版主 (文壇精英)
![]() |
專家經(jīng)驗: +518 |
金蟲 (正式寫手)
|
Generates K samples from the discrete distribution specified by weights 根據(jù)離散分布進(jìn)行采樣,該分布用樣本權(quán)重表示 rand(K,1)*cdf(end)的目的是:將產(chǎn)生的0-1之間的隨機數(shù),放縮到上述離散分布(因為權(quán)重weights的總和可能不等于1)。不妨假設(shè)rand(K,1)返回1,就容易理解它的含義了。 [0; cdf] 的含義與cumsum的具體實現(xiàn)有關(guān)。 |
金蟲 (正式寫手)
|
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)/2 len-1)/2].^2/(.4*len.^2);xx = [-(wid-1)/2 wid-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));%%%%%%%%%%%%在這里調(diào)用了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)); |
| 9 | 1/1 | 返回列表 |
| 最具人氣熱帖推薦 [查看全部] | 作者 | 回/看 | 最后發(fā)表 | |
|---|---|---|---|---|
|
[考博] 申博26年 +3 | 八6八68 2026-03-19 | 3/150 |
|
|---|---|---|---|---|
|
[考研] 288求調(diào)劑,一志愿華南理工大學(xué)071005 +5 | ioodiiij 2026-03-17 | 5/250 |
|
|
[考研] 【考研調(diào)劑】化學(xué)專業(yè) 281分,一志愿四川大學(xué),誠心求調(diào)劑 +5 | 吃吃吃才有意義 2026-03-19 | 5/250 |
|
|
[考研] 能源材料化學(xué)課題組招收碩士研究生8-10名 +4 | 脫穎而出 2026-03-16 | 12/600 |
|
|
[考研] 286求調(diào)劑 +6 | lemonzzn 2026-03-16 | 10/500 |
|
|
[考研] 324分 085600材料化工求調(diào)劑 +3 | llllkkkhh 2026-03-18 | 3/150 |
|
|
[考研] 287求調(diào)劑 +3 | 晨昏線與星海 2026-03-19 | 4/200 |
|
|
[考研] 0703化學(xué) 305求調(diào)劑 +4 | FY_yy 2026-03-14 | 4/200 |
|
|
[考研] 354求調(diào)劑 +4 | Tyoumou 2026-03-18 | 7/350 |
|
|
[考研] 070300化學(xué)319求調(diào)劑 +6 | 錦鯉0909 2026-03-17 | 6/300 |
|
|
[考研] 280求調(diào)劑 +6 | 咕嚕曉曉 2026-03-18 | 7/350 |
|
|
[考研] 材料,紡織,生物(0856、0710),化學(xué)招生啦 +3 | Eember. 2026-03-17 | 9/450 |
|
|
[考研] 考研求調(diào)劑 +3 | 橘頌. 2026-03-17 | 4/200 |
|
|
[考研] 308求調(diào)劑 +4 | 是Lupa啊 2026-03-16 | 4/200 |
|
|
[考研] 材料專碩326求調(diào)劑 +6 | 墨煜姒莘 2026-03-15 | 7/350 |
|
|
[考研] 326求調(diào)劑 +4 | 諾貝爾化學(xué)獎覬?/a> 2026-03-15 | 7/350 |
|
|
[考研] 321求調(diào)劑 +5 | 大米飯! 2026-03-15 | 5/250 |
|
|
[考研] 326求調(diào)劑 +3 | mlpqaz03 2026-03-15 | 3/150 |
|
|
[考研] 330求調(diào)劑 +3 | ?醬給調(diào)劑跪了 2026-03-13 | 3/150 |
|
|
[考研] 311求調(diào)劑 +3 | 冬十三 2026-03-13 | 3/150 |
|