Can't run function in ImageJ - function

I am a beginner with imageJ. I wanted to start using scripting tools, I started with writing a simple function as shown below, to mark a single pixel as white on the image already loaded into imageJ
function MarkPixel(x,y) {
setColor("white");
setLineWidth(1);
drawLine(x,y,x,y);
}
and I saved this as a file named 'MarkPixel.ijm' in the directory 'imageJ/macros'
Now I run imageJ, opened an image, start macro->interactive interpreter and run my function MarkPixel(0,0). But I get the error that says
Statement cannot begin with ')'.Then instead of interactive, I started a new macro window and entered my function there and tried running it. But still I get an error but different one this time, which says
Error: Undefined identifier in line 1:
<MarkPixel> ( 0 , 0 ) ;
Why this is not working for me? I feel like I will have to compile this function at some point, I have been reading through the documentation but couldn't find anything clearly yet.

Here is an ImageJ-macro that should do what you want:
newImage("Test", "8-bit black", 256, 256, 1);
point2white( 128, 128 ); // call the function
run("To Selection"); // for better visibility only
exit();
//
function point2white( xPos, yPos ) {
setForegroundColor(255, 255, 255);
makePoint( xPos, yPos );
run("Draw", "slice");
}
Paste the above macro code to an empty macro window
(Plugins >> New >> Macro) and run it.

Related

Dot sourcing a function call is not allowing me to call my function why could this be?

I am trying to write a module that calls on a script containing a series of functions I use in other modules. I have done this in the past with success but I seem to be stuck in a strange scenario, here is my situation:
When I copy the function code directly into my script and call it locally it works fine.
But when I
. <exact path to my function>
call to load my function it loads fine BUT when I then try to call a function in the file it throws an error stating the function does not exist but as I stated earlier when I copy the function into my script it executes just fine
My function is called NetworkScan
I have tried to convert the function to a module and use import-module this ends up with the exact same result
I have also tried to place the function script in the same location as my module and then set the location of my script to $PSScriptRoot and then using a . ./function.ps1 call also same issue (this where I am currently at)
Set-Location $PSScriptRoot
$ScannedIPs=#()
$RPIip= #()
$SIP = "192.168.220.1"
$EIP = "192.168.220.254"
#load function script
. .\function.ps1
$ScannedIPs = NetworkScan -SIP $SIP -EIP $EIP
....
this is a how my function NetworkScan is defined in function.ps1:
function NetworkScan{
Param(
[Parameter(Position = 0, Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[Alias("SIP")]
$StartScanIP,
[Alias("EIP")]
$EndScanIP)
....
}
expected results:
my function is called to pick up IP's on the network and their MAC addresses this is then returned to the module script to continue to process
Actual results:
NetworkScan : The term 'NetworkScan' is not recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Users\User\Downloads\Script_in_Dev\xxx_PowerCycler_10min.ps1:109 char:15
+ $ScannedIPs = NetworkScan -SIP $SIP -EIP $EIP
+ ~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (NetworkScan:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
EDIT:
I commented out all the other functions in my function.ps1 file and except for NetworkScan now I seem to be able to use NetworkScan via the above method however I would like to fix my function.ps1 file so I can use all the items in this file. Does anyone know why this would happen, being that I can load the file but not use any of this functions? As I am not getting syntax error its hard for me to understand where I went wrong if I could be pointed in the right direction I should be able to figure this out.

cocos2d-js: Error: Invalid Native Object using setPhysicsBody

I'm trying to implement chipmunk physics engine for a cocos2d-js game. I'm getting the following error when i run it.
jsb: ERROR: File Y:\Documents\cocos\PrebuiltRuntimeJs\frameworks\js-bindings\bindings\auto\jsb_cocos2dx_auto.cpp: Line: 2143, Function: js_cocos2dx_Node_setPhysicsBody
Invalid Native Object
JS: D:/PROJECTS/cocos/Sliderule/runtime/win32/../../src/app.js:32:Error: Invalid Native Object
Here is the code i'm working with
`init:function () {
this._super();
var size = cc.winSize;
this.rect1 = new cc.Sprite(res.null_png,cc.rect(0,0, 200, 25));
this.rect1.setColor(cc.color(255,50,50,1));
this.rect1.setPosition(size.width/2, size.height-12.5);
this.rect1._setAnchorX(0.5);
this.rect1._setAnchorY(0.5);
this.rectbody1 = new cp.Body(1,cp.momentForBox(1,this.rect1.getContentSize().width, this.rect1.getContentSize().height));
this.rectbody1.p = cc.p(size.width/2, size.height-12.5);
this.space.addBody(this.rectbody1);
this.rectshape1 = new cp.BoxShape(this.rectbody1, this.rect1.getContentSize().width - 14, this.rect1.getContentSize().height);
this.space.addShape(this.rectshape1);
this.rect1.setPhysicsBody(this.rectbody1);
this.addChild(this.rect1,1);
`
I get the problem when setting the body to the sprite. Thanks in Advance.
This error message usually appears because of a missing retain(). You have to explicitly set sprites to be kept by the native system (Android, iOS) otherwise it's not valid after some time. And then, if you don't need it anymore: release it.
Try:
this.rect1.retain()
after you created the sprite. And then
this.rect1.release()
when you don't need it anymore.

Three.js r68 on chrome shadows and uniforms failure to render mesh

I have a WebGL app using three.js. It has been running fine for months until today, September 7th, 2014.
It no longer runs on Chrome, however, it still continues to run on Firefox and Safari.
I have traced the problem to a specific condition.
I load objects from json files like this:
loader.load("assets/Tables.json", callback_mesh, "assets/maps/", parent.texturesTable);
The callback_mesh function looks like this:
var callback_mesh = function (result, materials, userData) {
for (var i = 0; i < materials.length; i++) {
if (materials[i].uniforms != undefined) {
materials[i].uniforms.tDiffuse.value = userData[TEXTURE_DIFFUSE];
materials[i].uniforms.tNormal.value = userData[TEXTURE_NORMAL];
materials[i].uniforms.tSpecular.value = userData[TEXTURE_SPECULAR];
}
}
var mesh = new THREE.Mesh(result, new THREE.MeshFaceMaterial(materials));
mesh.scale.set(1, 1, 1);
mesh.receiveShadow = true;
mesh.castShadow = true;
objects.push(mesh);
}
The above code no longer runs in Chrome.
If I remove the line "mesh.receiveShadow = true", it works fine.
If I create a new material, instead of using the materials from the json file and modifying their parameters/uniforms, I can leave the receiveShadow set to true and it works.
So the rather specific issue is when I import an object from a json file and assign the materials array that comes from the json file to the mesh as a MeshFaceMaterial and turn on receiveShadow, the object does not load and I get the following error message:
THREE.WebGLProgram: gl.getProgramInfoLog() (260,64-140): warning X3550: sampler array index must be a literal expression, forcing loop to unroll
(89,12): error X6077: texld/texldb/texldp/dsx/dsy instructions with r# as source cannot be used inside dynamic conditional 'if' blocks, dynamic conditional subroutine calls, or loop/rep with break*.
Failed to create D3D shaders.
three.js:25545
59WebGL: INVALID_OPERATION: getUniformLocation: program not linked three.js:25283
21WebGL: INVALID_OPERATION: getAttribLocation: program not linked
And, again, I never saw this prior to today, maybe there was a Chrome update. And it works fine under Firefox and Safari, the mesh loads with receiveShadows on and the shadows are rendered.
In the current Chrome, it works only if I turn off receiveShadows.
Anyone have this same problem or have any thoughts on what might be causing this?
Thanks.
-mat

How to show the song download represented by duration time of it

What i'm trying to do is to show the song download progress in form of song duration time. For example: 00:00, 01:05, 02:14, 03:58, .... 04:13 being 04:13 the song total duration. So far i have this code:
var soundClip:Sound;
var sTransform:SoundTransform = new SoundTransform(0.1);
function init() {
soundClip = new Sound();
soundClip.load(new URLRequest("magneto.mp3"));
//soundClip.load(new URLRequest("making.mp3"));
soundClip.addEventListener(Event.COMPLETE, soundLoaded);
soundClip.addEventListener(ProgressEvent.PROGRESS, soundLoading);
}
init();
function convertTime(millis:Number):String{
var displayMinutes:String;
var displaySeconds:String;
var Minutes:Number = (millis % (1000*60*60)/(1000*60));
var Seconds:Number = ((millis % (1000*60*60)) % (1000*60))/1000;
if(Minutes<10){
displayMinutes = "0"+Math.floor(Minutes);
}else{
displayMinutes = Math.floor(Minutes).toString();
}
if(Seconds<10){
displaySeconds = "0"+Math.floor(Seconds);
}else{
displaySeconds = Math.floor(Seconds).toString();
}
return displayMinutes + ":" + displaySeconds;
}
function soundLoaded(e:Event) {
soundClip.play(0,0,sTransform);
}
function soundLoading(e:ProgressEvent) {
trace(convertTime(soundClip.length));
}
As you can see, i'm testing it out with two songs, according to the code above the duration time of both are: 03:52 and 11:28 but according to the window these two songs last 03:52 and 05:44. Here is the code and both mp3 files.
Thank you.
EDIT:I'm analizing this page wicht play the song making.mp3, after debbuging it i realized that there is a value wicht is passed to the player, and go this way: 0, 0, 2664, 7576,...344370 these values are shown as*00:00, 01:05, 02:14, 03:58, .... 04:13* as the download progress. Knowing where this data come from would solve my problem, initially i thought it would be obtein through length propety but this only worked well for the magneto.mp3 file not for both songs.
On the whole i want to show:
00:00, 00:23, 01:23...03:57(where 03:57 is the duration time of any song) as the download progress.
Thank you for helping me. Cheers :)
Your code has no problems and your technique is correct.
You only need to fetch the total duration at the end of the download. The value of the file length changes as more data is retrieved. If your download stops before reaching the end, you will only have the length of the incomplete file. Add another handler possibly to check for errors, and if fired, let the user know that the file download is still incomplete.
Update: I figured it out. Add a call to convertTime() in the soundLoaded() method.
What is happening is that the file length is being updated in the PROGRESS event handler. But the final length is often only available in the COMPLETE event, because the PROGRESS event handler is called only when the file download is incomplete and not after it is ready.
Keep the convertTime() call in the PROGRESS event handler as you do presently.
private function soundLoaded(e:Event):void
{
soundClip.play(0, 0, sTransform);
trace(convertTime(soundClip.length));
}
This should do it.
Update 2: This is a known issue reported online at many forums. The length of any sound file sampled at less than 44 khz is reported incorrectly while the download is in progress. It's only after the download completes that the correct duration is reported. This only affects SWF files version 9 or less.
Changing the output SWF to version 10+ fixes the issue.

QR decode exceptions using ZXing.NET in Unity

I'm currently trying to make an application in Unity (for iOS) that allows a user to scan a QR code.
I am using the ZXing.NET library which has been optimized for Unity.
This is the current decode thread I am using
void DecodeQR()
{
// create a reader with a custom luminance source
var barcodeReader = new BarcodeReader {AutoRotate=false, TryHarder=false};
while (true)
{
if (isQuit)
break;
try
{
string result = "Cry if you see this.";
// decode the current frame
if (c != null){
print ("Start Decode!");
result = barcodeReader.Decode(c, W, H).Text; //This line of code is generating unknown exceptions for some arcane reason
print ("Got past decode!");
}
if (result != null)
{
LastResult = result;
print(result);
}
// Sleep a little bit and set the signal to get the next frame
c = null;
Thread.Sleep(200);
}
catch
{
continue;
}
}
}
The execution reaches the "Start Decode!" print statement, but fails to reach the "Got past decode!" statement.
This is because the Decode() method is generating an unknown exception every time, even when the camera is looking at a very clear QR code.
For reference:
c is of type Color32[] and is generated using WebCamTexture.GetPixels32()
W, H are integers representing the width and height of the camera texture.
For some reason, I cannot catch a generic Exception within the catch clause, meaning I cannot determine what kind of exception the Decode() method is generating.
EDIT: The code I have used is adapted from the Unity demo available from the ZXing.NET project. I am using the current version of ZXing.NET. I should also mention that I am currently testing this on an iMac, not on an iOS device or the simulator. I have tried running the Unity demo from scratch and I obtain the same result.
This is how the c variable (Color32[]) is updated:
void Update()
{
if (c == null)
{
c = camTexture.GetPixels32();
H = camTexture.height;
W = camTexture.width;
}
}
EDIT 2: I have separated the decode stage into two bits, firstly generating the result object then retrieving the text property of the result as shown:
if (c != null){
print ("Start Decode!");
var initResult = barcodeReader.Decode(c, W, H);
print ("Got past decode!");
result = initResult.Text; //This line of code is generating unknown exceptions for some arcane reason
print ("Got past text conversion!");
}
It is when the text value of the result is being retrieved that is causing the error. I still do not know how to fix it though.
Can someone please advise me?
Thanks
The code looks like the unity demo from the ZXing.Net project.
I tried the demo again with the current version 0.10.0.0. It works like a charm for me.
But I can only test it with unity on windows. I don't have a chance to try it with iOS.
Did you try the latest version of ZXing.Net? What version of unity do you use?
Is the variable c correctly set within the Update method?
I have solved the problem. The problem was that the texture being obtained from the camera was not in the correct aspect ratio and was 'squished'. As a result, the ZXing library could not properly recognise the code.
After correcting this issue, recognition worked flawlessly.