Re: Speed Improvement [message #74582] |
Tue, 25 January 2011 05:03  |
jeanh
Messages: 79 Registered: November 2009
|
Member |
|
|
Hi,
first, you are not using sCount anywhere... remove this loop
Instead of looping through all pixels, look for the needed ones
pixelsToProcess = where(PixelArr eq E_F_ATTNMAP_HIGH_PIXEL,
countPixToProcess)
sXYcol = array_indices(pixelArr, pixelsToProcess) ;get the 2D coords
for i=0L, countPixToProcess -1 do begin
;process
endfor
Jean
On 25/01/2011 4:24 AM, Rony K Varghese wrote:
> ;Processing a picture
> for sCount = 0, 9 do begin
> for sRow = UpperRow, LowerRow do begin
> for sCol = sLeftCol, sRightCol do begin
> ; Check whether high pixels.
> if E_F_ATTNMAP_HIGH_PIXEL eq PixelArr[sCol, sRow] then
> begin
> sXCol = sCol
> sYRow = sRow
> endif
> ; from the center to the left
> for sIndex = 0, sHalfWid do begin
> if HIGH_PIXEL eq vTemp[sXCol - sIndex, sYRow] then
> begin
> PixelArr[sXCol - sIndex, sYRow] = HIGH_PIXEL
> endif else begin
> break ; break from for sIndex
> endelse
> endfor
> ; from the center to the right
> for sIndex = 0, sHalfWid do begin
> if HIGH_PIXEL eq vTemp[sXCol + sIndex, sYRow] then
> begin
> PixelArr[sXCol + sIndex, sYRow] = HIGH_PIXEL
> endif else begin
> break ; break from for sIndex
> endelse
> endfor
> ; from the center to down
> for sIndex = 0, sHalfHght do begin
> if HIGH_PIXEL eq vTemp[sXCol, sYRow+ sIndex] then
> begin
> PixelArr[sXCol, sYRow+ sIndex] = HIGH_PIXEL
> endif else begin
> break ; break from for sIndex
> endelse
> endfor
> ; from the center to up
> for sIndex = 0, sHalfHght do begin
> if HIGH_PIXEL eq vTemp[sXCol, sYRow - sIndex] then
> begin
> PixelArr[sXCol, sYRow - sIndex] = HIGH_PIXEL
> endif else begin
> break ; break from for sIndex
> endelse
> endfor
> endfor; end for sCol
> endfor; end for sRow
> endfor;end for sCount
|
|
|
Re: Speed Improvement [message #74583 is a reply to message #74582] |
Tue, 25 January 2011 04:59   |
Jeremy Bailin
Messages: 618 Registered: April 2008
|
Senior Member |
|
|
On Jan 25, 4:24 am, Rony K Varghese <ronykvargh...@gmail.com> wrote:
> Dear All,
>
> How can i improve the speed of below IDL source through code
> optimizing..Now the performance is not satisfactory..
>
> ;Processing a picture
> for sCount = 0, 9 do begin
> for sRow = UpperRow, LowerRow do begin
> for sCol = sLeftCol, sRightCol do begin
> ; Check whether high pixels.
> if E_F_ATTNMAP_HIGH_PIXEL eq PixelArr[sCol, sRow] then
> begin
> sXCol = sCol
> sYRow = sRow
> endif
> ; from the center to the left
> for sIndex = 0, sHalfWid do begin
> if HIGH_PIXEL eq vTemp[sXCol - sIndex, sYRow] then
> begin
> PixelArr[sXCol - sIndex, sYRow] = HIGH_PIXEL
> endif else begin
> break ; break from for sIndex
> endelse
> endfor
> ; from the center to the right
> for sIndex = 0, sHalfWid do begin
> if HIGH_PIXEL eq vTemp[sXCol + sIndex, sYRow] then
> begin
> PixelArr[sXCol + sIndex, sYRow] = HIGH_PIXEL
> endif else begin
> break ; break from for sIndex
> endelse
> endfor
> ; from the center to down
> for sIndex = 0, sHalfHght do begin
> if HIGH_PIXEL eq vTemp[sXCol, sYRow+ sIndex] then
> begin
> PixelArr[sXCol, sYRow+ sIndex] = HIGH_PIXEL
> endif else begin
> break ; break from for sIndex
> endelse
> endfor
> ; from the center to up
> for sIndex = 0, sHalfHght do begin
> if HIGH_PIXEL eq vTemp[sXCol, sYRow - sIndex] then
> begin
> PixelArr[sXCol, sYRow - sIndex] = HIGH_PIXEL
> endif else begin
> break ; break from for sIndex
> endelse
> endfor
> endfor; end for sCol
> endfor; end for sRow
> endfor;end for sCount
>
> Thanks in advance..
> Rony
It might help if you could get a sketch of what this is supposed to
do.
-Jeremy.
|
|
|
Re: Speed Improvement [message #74619 is a reply to message #74582] |
Wed, 26 January 2011 19:56  |
Rony K Varghese
Messages: 3 Registered: January 2011
|
Junior Member |
|
|
On Jan 25, 10:03 pm, jeanh
<jghasb...@DELETETHIS.environmentalmodelers.ANDTHIS.com> wrote:
> Hi,
>
> first, you are not using sCount anywhere... remove this loop
>
> Instead of looping through all pixels, look for the needed ones
>
> pixelsToProcess = where(PixelArr eq E_F_ATTNMAP_HIGH_PIXEL,
> countPixToProcess)
>
> sXYcol = array_indices(pixelArr, pixelsToProcess) ;get the 2D coords
>
> for i=0L, countPixToProcess -1 do begin
> ;process
> endfor
>
> Jean
>
> On 25/01/2011 4:24 AM, Rony K Varghese wrote:
>
>
>
>
>
>
>
>> ;Processing a picture
>> for sCount = 0, 9 do begin
>> for sRow = UpperRow, LowerRow do begin
>> for sCol = sLeftCol, sRightCol do begin
>> ; Check whether high pixels.
>> if E_F_ATTNMAP_HIGH_PIXEL eq PixelArr[sCol, sRow] then
>> begin
>> sXCol = sCol
>> sYRow = sRow
>> endif
>> ; from the center to the left
>> for sIndex = 0, sHalfWid do begin
>> if HIGH_PIXEL eq vTemp[sXCol - sIndex, sYRow] then
>> begin
>> PixelArr[sXCol - sIndex, sYRow] = HIGH_PIXEL
>> endif else begin
>> break ; break from for sIndex
>> endelse
>> endfor
>> ; from the center to the right
>> for sIndex = 0, sHalfWid do begin
>> if HIGH_PIXEL eq vTemp[sXCol + sIndex, sYRow] then
>> begin
>> PixelArr[sXCol + sIndex, sYRow] = HIGH_PIXEL
>> endif else begin
>> break ; break from for sIndex
>> endelse
>> endfor
>> ; from the center to down
>> for sIndex = 0, sHalfHght do begin
>> if HIGH_PIXEL eq vTemp[sXCol, sYRow+ sIndex] then
>> begin
>> PixelArr[sXCol, sYRow+ sIndex] = HIGH_PIXEL
>> endif else begin
>> break ; break from for sIndex
>> endelse
>> endfor
>> ; from the center to up
>> for sIndex = 0, sHalfHght do begin
>> if HIGH_PIXEL eq vTemp[sXCol, sYRow - sIndex] then
>> begin
>> PixelArr[sXCol, sYRow - sIndex] = HIGH_PIXEL
>> endif else begin
>> break ; break from for sIndex
>> endelse
>> endfor
>> endfor; end for sCol
>> endfor; end for sRow
>> endfor;end for sCount
Thank you all for the help to me......
This function is to scan and process each pixel of the 128*128 picture
as in the source code.
I cannot remove the for loop of scount, because that much times the
code needs to be executed.
|
|
|
Re: Speed Improvement [message #74624 is a reply to message #74583] |
Wed, 26 January 2011 12:53  |
rogass
Messages: 200 Registered: April 2008
|
Senior Member |
|
|
On 25 Jan., 13:59, Jeremy Bailin <astroco...@gmail.com> wrote:
> On Jan 25, 4:24 am, Rony K Varghese <ronykvargh...@gmail.com> wrote:
>
>
>
>
>
>
>
>
>
>> Dear All,
>
>> How can i improve the speed of below IDL source through code
>> optimizing..Now the performance is not satisfactory..
>
>> ;Processing a picture
>> for sCount = 0, 9 do begin
>> for sRow = UpperRow, LowerRow do begin
>> for sCol = sLeftCol, sRightCol do begin
>> ; Check whether high pixels.
>> if E_F_ATTNMAP_HIGH_PIXEL eq PixelArr[sCol, sRow] then
>> begin
>> sXCol = sCol
>> sYRow = sRow
>> endif
>> ; from the center to the left
>> for sIndex = 0, sHalfWid do begin
>> if HIGH_PIXEL eq vTemp[sXCol - sIndex, sYRow] then
>> begin
>> PixelArr[sXCol - sIndex, sYRow] = HIGH_PIXEL
>> endif else begin
>> break ; break from for sIndex
>> endelse
>> endfor
>> ; from the center to the right
>> for sIndex = 0, sHalfWid do begin
>> if HIGH_PIXEL eq vTemp[sXCol + sIndex, sYRow] then
>> begin
>> PixelArr[sXCol + sIndex, sYRow] = HIGH_PIXEL
>> endif else begin
>> break ; break from for sIndex
>> endelse
>> endfor
>> ; from the center to down
>> for sIndex = 0, sHalfHght do begin
>> if HIGH_PIXEL eq vTemp[sXCol, sYRow+ sIndex] then
>> begin
>> PixelArr[sXCol, sYRow+ sIndex] = HIGH_PIXEL
>> endif else begin
>> break ; break from for sIndex
>> endelse
>> endfor
>> ; from the center to up
>> for sIndex = 0, sHalfHght do begin
>> if HIGH_PIXEL eq vTemp[sXCol, sYRow - sIndex] then
>> begin
>> PixelArr[sXCol, sYRow - sIndex] = HIGH_PIXEL
>> endif else begin
>> break ; break from for sIndex
>> endelse
>> endfor
>> endfor; end for sCol
>> endfor; end for sRow
>> endfor;end for sCount
>
>> Thanks in advance..
>> Rony
>
> It might help if you could get a sketch of what this is supposed to
> do.
>
> -Jeremy.
Same to me. If you want to perform a pattern matching maybe this
works:
width = 2*halfwid+ (((halfwid mod 2) eq 0?) 1 :0)
wh = where(convol(/edge_zero,vtemp,rebin([high_pixel],width,width ,/
samp)) $
eq (width*highpixel^2),c)
if c gt 0 then pixelarr[wh]=high_pixel
Cheers
CR
|
|
|