pixel level manipulation too slow and needs to work on larger image
''Can this code be made to work faster, it is very slow. Also, crashing a lot on images of larger size. It seems to work ok on some very small demo images, otherwise not good. What are the options? Extract each channel and read\write and then merge back together? I see a function\option of CopyInEntireArea ? , but no example code? Also what is FastAccess property?
Public Sub PixelOperationsTestColor() Dim im As McImage=ThisApplication.ActiveImage If im Is Nothing Then Exit Sub If im.NumberOfChannels=1 OrElse im.BitsPerChannel>8 Then Exit Sub'support only 8-bit color image 'create region access for whole image of color 8-bit image Dim ra As McRegionAccess=im.CreateRegionAccess() ra.RegionMask=im.Aoi'process only active ROI Dim data(,,) As Byte 'get 3D array of pixel data ra.GetArea(data) For c As Integer=0 To data.GetUpperBound(0) For i As Integer=0 To data.GetUpperBound(1) For j As Integer=0 To data.GetUpperBound(2) 'invert data(c,i,j)=255-data(c,i,j) Next Next Next 'put data back ra.PutArea(data) End Sub
0
Best Answer
-
In code view, on the project page, you add a reference to the compiled project then you can call macros and functions using the syntax <Compiled Project Name>.[Module Name].<Sub Name>.
Project Project1 Optimizer Off 'Add references to other projects using ReferenceProject. 'ReferenceProject "filename" ReferenceProject "..\Project3\Project3.ipp" LoadModule "Macros.vb" End Project
Public Sub CallProject3 Project3.Macro1 End Sub
Pierre0
Answers
-
Hello,
You can make this code run much faster by running it in a compiled project. You can either change the entire project to "compiled" on the project Properties page, or isolate this type of function in its own compiled project that can then be called from other interpreted projects. Compiled projects end up running native binary code so they could be hundreds times faster than interpreted ones.
FastAccesss would attempt to return the actual image memory if possible which would save 2 copies (no need for PutArea) but is not guaranteed to always succeed, depending on the image size the number of frames etc...
Pierre0 -
You can also use built in operations on images, check IMcOperations interface. Your sub can be replaced with this line:
ThisApplication.ActiveImage.Op.Not
You can use sequence of the operation on images to do the processing you need (Add, Sub, Mult,...).
Yuri
0 -
got it working as compiled project. How do I call a compiled project from another project?
0
Categories
- All Categories
- 961 Image-Pro v9 and higher
- 9 Image-Pro FAQs
- 18 Image-Pro Download & Install
- 448 Image-Pro General Discussions
- 486 Image-Pro Automation (Macros, Apps, Reports)
- 20 AutoQuant Deconvolution
- 2 AutoQuant Download & Install
- 18 AutoQuant General Discussions
- 195 Image-Pro Plus v7 and lower
- 3 Image-Pro Plus Download & Install
- 106 Image-Pro Plus General Discussions
- 86 Image-Pro Plus Automation with Macros
- 19 Legacy Products
- 16 Image-Pro Premier 3D General Discussions
- 26 Image-Pro Insight General Discussions