How can I solve an exception error for Batch image analysis using ImageJ - imagej

I am fairly new at ImageJ, but i managed beforehand to analyze aprox 720 images using the Batch->Macro feature, without any issues (I used the directionality plugin).
Now after a couple of days I am trying to use the Color Profiler plugin, which works perfectly fine when doing individual images, but when I use the same batch macro feature it gives me an Exception error for each image (I will attach the whole error).
Would you know a way to solve this issue?
I tried doing it both in classical ImageJ and also the FIJI version, but it seems to give the same issue.

I can replicate the problem and it seems as if the plugin needs to actually display the image which is not the case with batch processing. I didn't investigate the source code of this rather old plugin, but here is an ImageJ-macro that should do what you want (with some flickering):
//imagej-macro "batchColorProfiler" (Herbie G., 07. Jan. 2023)
requires( "1.54a" );
close("*");
run("Set Measurements...", " redirect=None decimal=2");
Dialog.create("Define input and output folder.");
Dialog.addDirectory("Where are your images?", getDir("file"));
Dialog.addDirectory("Where to store the plots and results?", getDir("file"));
Dialog.show();
in=Dialog.getString();
out=Dialog.getString();
f=getFileList(in);
for ( i=0; i<f.length; i++ ) {
if ( endsWith(f[i], "tif") ) {
path=in+f[i];
open(path);
cp(File.getNameWithoutExtension(path),out);
}
}
exit();
//
function cp(nme,dir) {
makeLine( 0, 20, 200, 120 ); // selection
run("Color Profiler");
IJ.renameResults(nme+"_results");
Table.save(dir+nme+"_results.csv");
close(nme+"_results"); // close table
nme=getTitle();
save(dir+nme+".tif");
close(); // close plot
close(getTitle()); // close image
}
//imagej-macro "batchColorProfiler" (Herbie G., 07. Jan. 2023)
Paste the macro code to an empty macro window
(Plugins >> New >> Macro) and run it.

Related

What are the actual differences between the print() vs debugPrint() and log() in Flutter?

I am trying to create a util for logging.
I need to know the actual differences between print() vs debugPrint() and log().
Many answers I have seen are outdated or confusing. Also, some upvoted answers are contradict.
I am trying to print error messages in red color. I am using ANSI code to achieve it.
debugPrint("\x1B[31m HelloDebug \x1B[0m");
The above one print in red color.
But when i do the same using log(), its not printing in red color. Its escaping the ANSI code.
One thing I found out was log() has error parameter.
If i pass something as error , it handles red color by default.
Here in the first one using log, red is not coming because ANSI code is ignored. But in debugPrint using it's working fine. In third one it takes error red by default. But extra line is added even for empty string message.
Code:
Output:
Is it possible use ANSI code for making color text using log?
Because I have other ANSI code to make different color text.
I dont want use debugPrint because if I print some thing too frequently , the system ignore the logs.
After digging some time I found out that log function is implemented in c++ in the dart runtime.As the log function is external function in dart sdk.
external void log(
String message, {
DateTime? time,
int? sequenceNumber,
int level = 0,
String name = '',
Zone? zone,
Object? error,
StackTrace? stackTrace,
});
https://github.com/dart-lang/sdk/blob/main/runtime/lib/developer.cc
Also I see some different answers while digging.
The below answer says debugPrint only available inside widget class. Is it still true?
https://stackoverflow.com/a/52241553/9248098
EDIT:
While using debugPrint and when I launch app from Android studio terminal, the ANSI color is working in android but when I run it same in iOS its escaping the characters in same Android Studio terminal.
If ANSI code support is based on terminal support, I couldn't figure out why its having issue in same terminal in iOS.
It is well explained in this page Debugging Flutter apps programmatically
debugPrint() is similar to print() but with a throttles applied to prevents being dropped by Android’s kernel.
If you have linter setup on VSCode or other IDE, you will see this warning whenever you use print in your code. For more information, you can refer to Avoid print calls in production code.
To avoid the lint error, you can use kDebugMode with print or debugPrint instead.
if (kDebugMode) {
print('test print');
}
// OR
debugPrint('test debugPrint');
As for log(), it actually allows you to include more information on the logging output. For example, you can add the runtimeType and the relevant object in the log that can help you in debugging the code.
log(
'test log',
name: runtimeType.toString(),
error: myObj,
);
** btw I tried log with ANSI code log("\x1B[31m HelloDebug \x1B[0m");, it is working as expected.

Can Dataflow sideInput be updated per window by reading a gcs bucket?

I’m currently creating a PCollectionView by reading filtering information from a gcs bucket and passing it as side input to different stages of my pipeline in order to filter the output. If the file in the gcs bucket changes, I want the currently running pipeline to use this new filter info. Is there a way to update this PCollectionView on each new window of data if my filter changes? I thought I could do it in a startBundle but I can’t figure out how or if it’s possible. Could you give an example if it is possible.
PCollectionView<Map<String, TagObject>>
tagMapView =
pipeline.apply(TextIO.Read.named("TagListTextRead")
.from("gs://tag-list-bucket/tag-list.json"))
.apply(ParDo.named("TagsToTagMap").of(new Tags.BuildTagListMapFn()))
.apply("MakeTagMapView", View.asSingleton());
PCollection<String>
windowedData =
pipeline.apply(PubsubIO.Read.topic("myTopic"))
.apply(Window.<String>into(
SlidingWindows.of(Duration.standardMinutes(15))
.every(Duration.standardSeconds(31))));
PCollection<MY_DATA>
lineData = windowedData
.apply(ParDo.named("ExtractJsonObject")
.withSideInputs(tagMapView)
.of(new ExtractJsonObjectFn()));
You probably want something like "use an at most a 1-minute-old version of the filter as a side input" (since in theory the file can change frequently, unpredictably, and independently from your pipeline - so there's no way really to completely synchronize changes of the file with the behavior of the pipeline).
Here's a (granted, rather clumsy) solution I was able to come up with. It relies on the fact that side inputs are implicitly also keyed by window. In this solution we're going to create a side input windowed into 1-minute fixed windows, where each window will contain a single value of the tag map, derived from the filter file as-of some moment inside that window.
PCollection<Long> ticks = p
// Produce 1 "tick" per second
.apply(CountingInput.unbounded().withRate(1, Duration.standardSeconds(1)))
// Window the ticks into 1-minute windows
.apply(Window.into(FixedWindows.of(Duration.standardMinutes(1))))
// Use an arbitrary per-window combiner to reduce to 1 element per window
.apply(Count.globally());
// Produce a collection of tag maps, 1 per each 1-minute window
PCollectionView<TagMap> tagMapView = ticks
.apply(MapElements.via((Long ignored) -> {
... manually read the json file as a TagMap ...
}))
.apply(View.asSingleton());
This pattern (joining against slowly changing external data as a side input) is coming up repeatedly, and the solution I'm proposing here is far from perfect, I wish we had better support for this in the programming model. I've filed a BEAM JIRA issue to track this.

ZBar processor and delphi

Ok so I have been trying to get bar code scanning to work in a delphi application for the last 3 weeks now. Ive been directed to this example but that example uses other librarys like imagemagika and is a console application. I am looking for a vcl forms application.
Here is some code I have written to try and see if I can get the ZBar processor to work in delphi :
// Create Processor
processor := zbar_processor_create(0);
zbar_processor_set_config(processor, ZBAR_NONE, ZBAR_CFG_ENABLE, 1);
// Initialize processor
zbar_processor_init(processor, {what do I put here ?}, 1);
// Setup a callback
{I dont know what do here}
// Enable preview window
zbar_processor_set_visible(processor, 1);
zbar_processor_set_active(processor, 1);
This code is based on a example in C that I found here : https://github.com/ZBar/ZBar/blob/master/examples/processor.c
as well as the documentation over here :
http://zbar.sourceforge.net/api/zbar_8h.html#c-processor
The zbar window opens but it does not show the video feed because I parsed nil as a paramater in the initialize step. In the example they have this C code but I have no idea what it means :
const char *device = "/dev/video0";
/* initialize the Processor */
if(argc > 1)
device = argv[1];
zbar_processor_init(proc, device, 1);
If I parse '/dev/video0' instead of nil the video feed still doesn't show. So I guess my question is what do I need to parse in zbar_processor_init() function ?
I also dont know how to set up a callback function that will be called once a result is found. How would I go about doing this ?
Thanks in advance,
Kobus
argc is the number of parameters passed in the command line and argv fetches them. dev/video is linux style device. Try con:
zbar_processor_init(processor, 'con:', 1)
Con: is the console. Com1: serial port 1, Aux: auxiliary port - probably usb, Prn: the printer Lpt: the line printer.

Conditional OCR rotation on the image or Page in KOFAX

We have two source of inputs to create a Batch first is Folder Import and second is Email import.
I need to add condition where if the source of image is Email it should not allow to rotate the image and like wise if source if Folder import it should rotate the image.
I have added a script for this in KTM.
It is showing proper message of the source of image but it is not stopping the rotation of the image.
Below check the below script for reference.
Public Function setRotationRule(ByVal pXDoc As CASCADELib.CscXDocument) As String
Dim i As Integer
Dim FullPath As String
Dim PathArry() As String
Dim xfolder As CscXFolder
Set xfolder = pXDoc.ParentFolder
While Not xfolder.IsRootFolder
Set xfolder = xfolder.ParentFolder
Wend
'Added for KTM script testing
FullPath= "F:\Emailmport\dilipnikam#gmail.com_09-01-2014_10-02-37\dfdsg.pdf"'
If xfolder.XValues.ItemExists("AC_FIELD_OriginalFileName") Then
FullPath= xfolder.XValues.ItemByName("AC_FIELD_OriginalFileName").Value
End If
PathArry() = Split(FullPath,"\")
MsgBox(PathArry(1))
If Not PathArry(1) = "EmailImport" Then
For i = 0 To pXDoc.CDoc.Pages.Count - 1
pXDoc.CDoc.Pages(i).Rotation = Csc_RT_NoRotation
Next i
End If
End Function
The KTM Scripting Help has a misleading topic named "Dynamically Suppress Orientation Detection for Full Page OCR" where it shows setting Csc_RT_NoRotation from the Document_AfterClassifyXDoc event.
The reason I think this is misleading is because rotation may already have occurred before that event and thus setting the property has no effect. This can happen if layout classification has run, or if OCR has run (which can be triggered by content classification, or if any project-level locators need OCR). The sample in that topic does suggest that it is only for use when classifiers are not used, but it could be explained better.
The code you've shown would be best called from the event Document_BeforeProcessXDoc. This will run before the entire classify phase (including project-level locators), ensuring that rotation could not have already occurred.
Of course, also make sure this isn't because of a typo or anything else preventing the code from actually executing, as mentioned in the comments.

Inserting delay after imshow function in opencv

I would like to show an image in opencv. I create a window using "namedWindow" and show the image using "imshow". at the end of the code I use "cin" so the program does not quit automatically. part of my code looks like this:
namedWindow("image");
imshow("image",aa);
waitKey(500);
cin >> aaa;
return 0;
If I eliminate the waitKey statement, I cannot see the image. Why is it like that ? the next statement (cin >> aaa) is not executed after imshow is done ? why is a delay essential?
it's not so much the delay, that's essential, but more the hidden functionality inside waitkey.
imshow will just copy the image, but waitkey will finally blit it ( or , send out the messages to your os nessecary for doing so )
so you need to call waitkey in any case, if you use imshow. 1(millisecond) is the smallest value you can put here for continuous rendering, 0 or -1 will block until you press a key.
besides, waitkey listens to keypresses in that img-window, cin listens to input from the console window.
cv::WaitKEy(0) the image will stay there

Resources