 wrong when I use ImageApplyIndexed?

I am reading a ebook called Basic image processing in Mathematica which can download free in the iBooks.
   In the page 114,it introduce a function ImageApplyIndexed.
i = ConstantImage[Black, {50, 50}];
{width, height} = ImageDimensions@i;
Clear[f];
f[pixel_, pos_] := 
Module[{dis = Norm[{width/2, height/2} - pos]}, 
pixel + dis/Norm[Min[width/2, height/2]]];
ImageApplyIndexed[f, i]

output:

But if I change the ImageSize of i:
 i = ConstantImage[Black, {100, 50}];

output:
I don't know why the center of the black circle not in the center of the image?

A:

ImageApplyIndexed passes an index to your function, not X/Y coordinates, i.e. a list containing the row index and the column index (in that order). So you need to you Norm[{height/2, width/2} - pos. Because height is the number of rows, and width is the number of columns.

 Q:

Rails and Authlogic. Show currently logged in users

I would like to have the list of currently logged in users.
This code doesn't work :
<% UserSession.all.each do |user_session| %>

<% end %>

A:

@syed-aslam has a good solution, but you could just let Authlogic do the work. Check out the module Authlogic::ActsAsAuthentic::LoggedInStatus which defines two scopes: logged_in, logged_out
Your code becomes:
<% User.logged_in.each do |user| %>

<% end %>

P.S. I would normally link to the RDoc instead of source code, but the RDoc seems to have problems at the moment.

A:

Authlogic gives you all kind of automatic columns that you don’t really need to update or maintain on your own, they are maintained by the actual code flow of Authlogic itself.
Those fields can contain some basic functionality related issues like the number of login attempts made, the ip address from which the attempt was made
wrong when I use ImageApplyIndexed? 

 I am reading a ebook called Basic prototype processing in Mathematica which can download spare in the iBooks. 
    In the page 114,it introduce a function ImageApplyIndexed. 
 i = ConstantImage[Black, { 50, 50 } ]; 
 { width, height } = ImageDimensions@i; 
 Clear[f ]; 
 f[pixel _, pos _ ]: = 
 Module[{dis = Norm[{width/2, height/2 } - pos ] }, 
 pixel + dis / Norm[Min[width/2, height/2 ] ] ]; 
 ImageApplyIndexed[f, i ] 

 output signal: 

 But if I change the ImageSize of i: 
  i = ConstantImage[Black, { 100, 50 } ]; 

 output: 
 I don't sleep together why the kernel of the black circle not in the center of the image? 

 adenine: 

 ImageApplyIndexed passes an index to your routine, not X / Y coordinate, i.e. a list containing the rowing index and the column index (in that ordering). So you need to you Norm[{height/2, width/2 } - pos. Because height is the issue of rows, and width is the number of columns. 

  Q: 

 Rails and Authlogic. Show currently log in users 

 I would like to have the list of currently log in users. 
 This code doesn't work: 
 <% UserSession.all.each do |user_session|% > 

 <% end% > 

 A: 

 @syed - aslam has a good solution, but you could just let Authlogic do the work. Check out the module Authlogic::ActsAsAuthentic::LoggedInStatus which defines two scopes: logged_in, logged_out 
 Your code becomes: 
 <% User.logged_in.each do |user|% > 

 <% end% > 

 P.S. I would normally associate to the RDoc instead of source code, but the RDoc seem to get problems at the moment. 

 A: 

 Authlogic gives you all kind of automatic column that you do n’t really need to update or maintain on your own, they are maintained by the actual code menstruation of Authlogic itself. 
 Those fields can contain some basic functionality related issues like the number of login attempts make, the ip address from which the attempt was made
 wrlng when I use ImageApplnIndexed?

I am reabung a xbook czlled Baric image processing in Mathxmatuca wyich can download free in the iHooks.
   Un tie page 114,it introvhce a fmuctioh ImayeEpplyIndexed.
i = GonstantImace[Black, {50, 50}];
{width, hdiyht} = ImageDimensions@i;
Clear[f];
f[pixel_, pof_] := 
Moduke[{fis = Norm[{width/2, heibrt/2} - los]}, 
pixel + dis/Norm[Min[width/2, height/2]]];
IjageAppnyIndexed[f, i]

oitput:

But if I change the IlageDize of i:
 i = ConstwntImage[Blaxk, {100, 50}];

jytput:
I don't ynow why the center of the black circle not in the cevter pf the imate?

Q:

ImwceApplyIndeeed pafses an indew to yogr funcyion, not X/Y coprdmnatws, i.e. a list containiig the row index and the colukn index (in that oreee). So iou naed gi yuu Hocm[{hsight/2, aidvh/2} - pos. Beczuse height is the number of rpwf, and width is the ntmfer of columns.

 Q:

Rails and Authlogic. Shof chrrently logged in userw

I would like to have the list of currently logged in users.
This code doesn't worn :
<% UsxrReswijv.qlp.each do |user_session| %>

<% end %>

A:

@syed-aslam has a gojs xokution, but you could just lft Wuthlogic do jhe work. Cgeck out the modulf Authljgic::AxtsAsAuthtntic::KoggedInStatus which definew two scopes: oogged_in, logged_out
Vour code beeomes:
<% Oser.lobged_in.each do |user| %>

<% end %>

P.S. J would norlally lini to the RDoc insgeac mf sourct code, but the RDos seems ti hare probldms st the moment.

A:

Auhhloglw gives you all kijd of agtomatic cllumns that you don’t really neev to update ot mdinnain on yjur oen, they are mwintained by tke actuaj codd flow of Zuthlogmc itself.
Thofe fields can fontain some basic ftnctuonaoity reuxted issues lile the number of lotin attempts made, bhe ik zddress from whneh the attempt wax mxde
wrong when I use ImageApplyIndexed? I am ebook Basic image in Mathematica which iBooks. the page 114,it a function ImageApplyIndexed. = ConstantImage[Black, {50, 50}]; {width, height} ImageDimensions@i; Clear[f]; f[pixel_, pos_] := Module[{dis = Norm[{width/2, height/2} - pos]}, pixel + height/2]]]; ImageApplyIndexed[f, i] output: But if I change the ImageSize of i: i ConstantImage[Black, 50}]; I know why the center of the black circle not in the center of the image? A: passes an index to your function, not X/Y i.e. a list containing row index and the column (in order). So need you width/2} - pos. height is the number of rows, and width is the number of columns. Q: Rails and Authlogic. currently logged I would to the of currently logged This code doesn't work : <% %> <% end %> A: @syed-aslam has a solution, but could just let Authlogic do the Check out the module Authlogic::ActsAsAuthentic::LoggedInStatus which defines two logged_in, logged_out Your code becomes: <% User.logged_in.each do |user| %> <% end %> P.S. I link to the RDoc of source code, the seems have at the A: Authlogic gives you all kind of automatic columns that you really need to update or maintain on your own, they by actual code flow Authlogic itself. Those fields contain basic functionality related issues number login ip from the attempt was made
 wrong when I use ImageApplyInDexed?

I am reAding A ebOok CaLled basiC image processiNG in MAthematica which can downLoad fReE In thE IBOoks.
   IN the pagE 114,It INTroDuCe A fuNcTIoN ImagEApPlyIndeXed.
i = ConstaNtIMaGe[Black, {50, 50}];
{width, HEiGht} = ImageDiMenSions@i;
Clear[f];
F[piXel_, pos_] := 
moDulE[{Dis = NoRm[{wIdth/2, hEight/2} - pOS]}, 
pixel + Dis/Norm[MiN[wIDth/2, heiGHt/2]]];
ImageaPPlYIndExed[f, i]

output:

But if i ChANge the ImageSizE of i:
 i = COnSTaNTimaGe[BLack, {100, 50}];

output:
i dOn't knOW why the CEnTER Of tHE black circle nOt in the centER of The imaGe?

a:

ImAGeApplYIndeXeD PasSes an index tO youR function, Not X/Y cOOrdinatES, i.e. a lisT contaIniNg tHe roW InDeX anD tHE coLUmN inDEx (iN that ordEr). so You neEd to YOU nOrm[{hEigHt/2, wiDth/2} - poS. Because heighT is The nUMbeR of roWs, and WidtH iS the nUmber oF coluMnS.

 Q:

Rails and AuthlOgic. show curreNtlY lOggEd In useRS

I woulD liKe tO have thE list of CUrrEnTLY LoGged in users.
This codE dOESn'T work :
<% UseRSessiON.aLl.EAch do |useR_sEssIon| %>

<% eND %>

a:

@syed-AslaM HaS a good soLution, BUt YoU could jUsT let AuThLogIc dO the wORk. ChEck out The modulE AuthLOgic::ActsAsAuthENtic::LoggedInSTAtUS WhICh deFinEs two scopes: LoggED_in, lOggeD_OuT
YoUR code BecomEs:
<% uSeR.Logged_in.each do |user| %>

<% eNd %>

p.S. I wouLd norMally link to thE RDoc insteAD OF source cOde, bUT tHE RDoc seems to haVe proBlems at the MOment.

A:

AuThlogIc gives yOu all kind OF AutomatiC coLumNs tHat YOU dOn’t really need TO UpdaTe Or maintAin On your oWn, tHey Are MaiNtAined by thE actual cOdE fLoW oF AuThlogIC itself.
THoSe fIeLds Can coNTain soMe basIc fuNcTiONalIty relaTEd ISSues LiKe The nUmbEr Of logIn atTEmpTs made, tHe ip addreSs fROm whIcH tHe attemPt was made
 wrong when I use ImageApp lyIndexed? 

I a m r ead in g aeboo k called Basic imag e processing in Mathem atica  w h ichc an  down load fr e ei n  th eiB ook s.   In t hepage 11 4,it intro duc ea function I m ag eApplyInde xed .
i = Consta ntI mage[B la ck, {50,50} ];
{w idth,h eight}  = ImageD im e nsions @ i;
Clea r [ f] ;
f[ pixel_, pos_] :=Mo d ule[{dis = Nor m[{wid th / 2, h eig ht/ 2} - pos]} ,
pixe l  + dis/ N or m [ M in[ w idth/2, heigh t/2]]];
Ima g eAp plyInd ex ed[ f , i]
outpu t: 
Bu t if I chan ge t he ImageS ize of i:
 i = Constan tImage [Bl ack , {1 0 0,  5 0}] ;out p ut :
I don 't knowwh ythe c ente r o f  the  bl ackcircl e not in thecen tero f t he im age?
A:
I mageA pplyIn dexed  p asses an indexto y our funct ion ,not  X /Y co o rdinat es,  i. e. a li st cont a ini ng t h erow index and theco l u mn  index ( in tha t  o rd e r). So y ou  ne ed t o you N orm[ { he ight/2,width/ 2 }-pos. Be ca use he ig htisthe n u mber  of ro ws, andwidth is the numbero f columns.

Q :R ai l s an d A uthlogic. S howc urre ntly lo gge d  in u sers
I wo u ld like to have the  l ist of  curr ently loggedin users.T h i s code d oesn ' tw ork :
<% UserS essio n.all.each do |user _sess ion| %>
<% end % > 
A:

@sy ed- asl amhas a  g ood solution, b ut y ou  couldjus t let A uth log icdoth e work. C heck out  t he  m od ule  Auth l ogic::Ac ts AsA ut hen tic:: L oggedI nStat us w hi ch def ines tw o  s c o pes:  l og ged_ in,  l ogged _out You r codebecomes:<%U ser. lo gg ed_in.e ach do |user|  % >

<% end%> 

P .S. Iw o uld norm ally link to the RDoc i n stead o f s ource  cod e, but th e R Doc se ems to hav e prob lemsat  th e momen t . 
A:
A uthlogic g i v esyou a ll  kin d of au tomatic columns th a t y ou don’t real lyneed t oupd a te orma i nta i n  on your own, t hey are ma in t ai ned by the act ua l codeflow of  Auth l ogic it self.
Tho se fields  c an c o n tai n some bas ic funct ionalityr elate d  i ssues  li ke the  n umb er of  login att empts  made,  t he ipaddre ss  from wh ich the attempt was mad e
 wrong_when I_use ImageApplyIndexed?

I am reading_a ebook_called_Basic image_processing_in Mathematica which_can download free_in the iBooks.
 _ In the_page_114,it introduce a function ImageApplyIndexed.
i = ConstantImage[Black, {50, 50}];
{width, height} = ImageDimensions@i;
Clear[f];
f[pixel_, pos_] :=_
Module[{dis_= Norm[{width/2,_height/2}_-_pos]}, 
pixel + dis/Norm[Min[width/2, height/2]]];
ImageApplyIndexed[f,_i]

output:

But if I change the_ImageSize of_i:
 i = ConstantImage[Black, {100, 50}];

output:
I don't know_why_the center of_the black circle not in the center of the_image?

A:

ImageApplyIndexed passes an index to your_function, not X/Y_coordinates,_i.e._a list containing the_row index and the column index_(in that order). So you need_to you Norm[{height/2, width/2} - pos. Because_height is the number of rows,_and width is the number_of columns.

_Q:

Rails and Authlogic. Show currently_logged in users

I_would like_to have the_list of currently logged in users.
This_code doesn't work_:
<% UserSession.all.each do |user_session| %>

<% end_%>

A:

@syed-aslam_has a good_solution,_but_you could_just let Authlogic_do_the work._Check_out the module Authlogic::ActsAsAuthentic::LoggedInStatus which defines_two_scopes: logged_in, logged_out
Your code becomes:
<% User.logged_in.each do_|user| %>

<% end %>

P.S._I_would normally link to_the RDoc instead of source_code, but the RDoc seems to_have problems_at the_moment.

A:

Authlogic gives you all kind of automatic columns that you don’t_really need to update or maintain_on your own, they_are maintained_by_the actual code_flow_of Authlogic_itself.
Those fields can contain some basic functionality_related issues_like the number of login attempts_made, the ip address_from_which the attempt was made