I am trying to build a simple java app, which would count particles and then display their number. I am using imagej (ij.jar) library, everything works perfect until the little box with result is supposed to be shown. COuld anyone pease explain to me how can I display that. And the second thing, how do I extract that value to an int.
my current code:
button action, which leads to:
ImagePlus imp = IJ.openImage("C:\\Users\\bibaleze69\\Desktop\\imageprocessing\\chromosomes2.jpg");
imp1.show();
IJ.run(imp, "Color Threshold...", "");
IJ.run(imp, "Analyze Particles...", "show=[Overlay Outlines] display summarize");
how do I extract that value to an int.
I believe you want to use the Results Table API. ResultsTable.getResultsTable will get the active results after your Analyze Particles command, and you can then interrogate it with the getValue methods.
COuld anyone pease explain to me how can I display that
I think your Analyze Particles isn't running because running Color Threshold... doesn't actually apply the threshold to create a mask or 8-bit image, it just opens the thresholding interface. I actually had a lot of trouble trying to get the Color Threshold to apply. I think you have a couple options though:
If you run Color Threshold in Fiji, and open the Macro Recorder, you can press the "Macro" button in the Color Threshold dialog to dump a ton of IJ1 Macro code to the recorder. This code will actually apply the selected threshold to your image and create an image that can then be input to Analyze Particles. But you would have to replicate this process on the Java side and I don't know how flexible it will be.
Alternately, you can adapt the following IJ1 Macro code to just threshold the image as 8-bit.
run("8-bit");
setAutoThreshold("Default");
//run("Threshold...");
setOption("BlackBackground", false);
run("Convert to Mask");
If you can get the desired threshold from just operating on an 8-bit version of your image then this is a much simpler option to get your data to Analyze Particles.
If these options don't fully work for you, I would also recommend writing to the ImageJ mailing list, which is read by the Threshold Colour author, among many others.
Related
I want to know if there is any solution for the following scenario:
I have an application which uploads the files, after scanning and transcoding them, onto a server. Suppose, an image file is being uploaded which has been tampered with some additional contents over it. Now, as the uploaded file is illegitimate, I want to remove the additional tampered contents and upload just the original part of this image file. Is it possible to do so in Java?
Thanks.
It's not possible to detect in the general case, but there are some heuristic methods available to determine whether an image has been edited. Try using the tools at http://imageedited.com/ to get an idea of what's possible.
Removing the edit is a much more difficult problem, which is probably impossible with current methods.
I'm just speculating here, and I don't know how well it would work in practice, but you could do it if you limit to specific sources of tampering. E.g., suppose you want to remove the logo added to an image by memegenerator.net.
You know in advance what the text looks like and where it is. Create a transparent png template that matches the text. Then sum the differences between the image and template pixel colors, multiplying each by the alpha of the template pixel. Since for this particular logo, it's basically white (although it seems to have a thin black shadow) you would get false positives for a picture with a white part there, so you'd also need to verify that the surrounding pixels are (within a tolerance) not white. It's not clever but it could work for certain sites.
For anything more flexible (e.g., logos on images which have subsequently been resized) you're in to the territory of OCR and TinEye-like image matching, which are more advanced than I could advise you on.
To correctly detect all kinds of "tampering" and filter "illegitimate" from "legitimate" in general, you'd need an artificial intelligence that could understand the meaning and context of what it's seeing. The short answer is: you can't. That's what humans are for.
If this is for a website, probably the best thing you can do is a report button that lets users of your site report images that don't fit with your site's rules.
I am working on a research project.The scenario is this.
I am taking the screenshot of my desktop and then I process it using an API to get the position of a certain text on my Desktop.e.g , say I have the browser open on my desktop and I am on stackoverflow.Now I want to search the position of the logo stackoverflow on the screenshot taken.Then I want to simulate a click on it.I am using Java platform.
Now I have 2 questions:
1)Is there any free API(OCR) which I can use to process the screenshot to fetch text position (or can be done by some trick) and gives good results.
Or Any way you can suggest that I can use (instead of taking screenshot and processing it) to get the position of any text on the screen.
2)How can I simulate the click on the screen using the code by a background program running(I mean I have done it in Swing and other language UIs but this time its different as Now I want to click on the screen.
If I understood you right you want to move your mouse and click on the screen. That not that hard you could use the robot class from Java!
For example:
Robot rob = new Robot();
rob.keyPress( KeyEvent.VK_ENTER );
or what ever, there are so much bottons and movements you could with it. A list of all methods you find here.
And your other question I can't answer. I think there is no API that is able to search a text and give you the position. But what I know is that the robot class is able to capture the screen and put it into a BufferedImage. With it you could compare two pictures.
Maybe you could get use of this but I don't know if it is what you search.
We have a requirement where we already have pre printed stationery and want user to put data in a HTML form and be able to print data on that form. Alignment/text size etc are very important since the pre-printed stationery already has boxes for each character. What could be a good way to achieve this in java? I have thinking of using jasper reports. Any other options? May be overlay image with text or something?
Also we might need to capability to print on plain paper in which case the boxes needs to be printed by our application and the form should match after the printed with the already printed blank stationery containing data.
Do we have some open source framework to do such stuff?
Jaspersoft reports -- http://sourceforge.net/projects/jasperreports/
You will then create XML templates, then you will be able to produce a report in PDF, HTML, CSV, XLS, TXT, RTF, and more. It has all the necessary options to customize the report. Used it before and recommend it.
You will create the templates with iReport then write the code for the engine to pass the data in different possible ways.
check http://www.jaspersoft.com/jasperreports
Edit:
You can have background images and overlay the boxes over it and set a limit on the max character size ... and many more
It is very powerful and gives you plenty of options
Here is one of iReport's tutorial for a background image http://ireport-tutorial.blogspot.com/2008/12/background-image-in-ireport.html
The big problem when printing form content that has been filled in electronically, is aligning it correctly on the pre-printed form. You may get content to align for one printer, but when you use another it is completely misaligned.
Fly Software have a form design product called InForm Designer that gets around the problem nicely by allowing users to specify and save vertical and horizontal offsets for printers. This ensures filled in form content is always aligned. I've tried it and it works perfectly. Take a look for yourself here...
http://www.flysoftware.com/products/inform_designer/overview.asp
It might be worth implementing a printer offset similar to InForm's in your own application (if possible).
Some things to think about.
First in terms of the web page, do you want use the stationery as the form layout?
Does it have to be exact?
Combed boxes (one for each character)
Do you want to show it like that on the web page, or deal with the combing later.
How are you going to deal with say a combed 6 digit number. Is this right aligned. What if they enter 7 digits. Same for text. what if it won't fit.
Font choices, we had a lot of fun with W...
How aligned do you want the character within the box, what font limitations does that imply, some of the auto magic software we looked at did crap like change the size of each character.
Combed editing is a nightmare, we display combed, but raise an edit surface the size of the full box on selection.
Another thing that might drive you barking mad, you find find small differences in the size and layout of the boxes, so they look okay from a distance but a column of boxes sort of shifts about by a pixel. Some of testing guys had to lend us their electron microscopes, so we could see how many ink molecules we were out by. :(
Expect to spend a lot of time in the UI side of things, and remember printed stationery changes, so giving yourself some sort of meta description of the form to start with will save you loads of trouble later on.
I want to use the auto-color tool (photoshop, under Image tab) on the android.
Is their a way to implement this tool/option into android with code or does android already has this kind of option in a librabry?
So when I open a picture, then when I hit a button, it should use the auto-color on the image (ImageView).
Thanks for the help already
this is the problem:
I got a green scanner, it is a scanner that scans the pixels green, and then shows the % green that is on the image.
However when you take a picture of some grass when the sun is shining the app detects more green then you take one in the shadow, but in real, their is the same amount of green (grass).
And with the tool in photoshop (auto-color) it manipulates the "sun" really good, after few pictures (tests) the auto-color does it better then when I do it manually, so that is the reason I want to try to get this tool on the android somehow.
I didn't tried to implement auto-color in the android yet because I just don't if their is something like that. I now have 2 pictures (taken at same time, 1 in shadow and 1 in the sun) and I try to manipulate the one that I took in the sun, so it looks like the one taking in the shadow. So it gives (almost) the same amount of % green with my green scanner app.
PS, Mine Internet connection goes down now for few minutes, so I maybe won't see this post (answers) right-away
I'm not aware of any build-in way to do this on Android, so you'll probably have to do the algorithm yourself.
But, you could start off by getting inspired on how Gimp does it, by looking through the source code. Otherwise wikipedia has a good article on the subject - http://en.wikipedia.org/wiki/Color_balance
Is it possible to make Java program that will determine the absolute position (x,y on screen) of blinking keyboard cursor? That cursor can be in any text editor.
Not easily, since the position of a cursor on a screen of a program is merely a data point inside that program and rendering that cursor is a method running in the program. (I'm reading your question to mean that the program/editor in question is a wholly separate process from your Java program, right?)
You can theoretically do it if:
The program explicitly exports via some API calls the cursor location
You capture the actual screengrabs of that program very fast, analyze the image difference, and deduce cursor location from appearing/disappearing rectangle or short line in case the screen of the program didn't change save for cursor blink.
If you need relative (e.g. in # of chars instead of # of pixels) location in an editor, then somehow use edge recognition to detect editor size, some advanced image processing magic to deduce font size, and compute character-based offsets.
If the editor is using standard OS (e.g. Windows) APIs to draw both editing window AND the cursor, it might theoretically be plausible to hook into the system to intercept those calls - i don't posess nearly the amount of knowledge of what those APIs might be or if such even exist, how possible it is to intercept them, and whether Java programs are able to do that even if it's possible theoretically.
The question here is not whatever is possible or not, the question is for what purpose should i want to do this? Frankly, i don't see any reason, and i am sick of annoying mini-apps who act like spyware. Are u trying to duplicate the existent app into another form of mass terror?
I beg your pardon if u find my comment offensive, but this is my answer. Another question : why?