OpenCV - Removing noise from image - java

This is my image:
I want to remove the the noise(little black unrelated pixels) from my image.
I tried gaussian, cvtColor and adaptiveThreshold but none did the job.
Ideas? If you have a code in java that will help.

Noise removal could be tricky depending on the application. for your image a simple morphology operation like closing/Opening could solve the problem. Opening operation helps to remove the noises in your image. Closing will help to fill the existing holes.
Since OpenCV c++ APIs are like Java you can use the following:
cv::Mat Kernel = cv::Mat(cv::Size(Maximum_Width_of_Noise,Maximum_Height_of_noise),CV_8UC1,cv::Scalar(255));
cv::morphologyEx(Input_Image,temp,cv::MORPH_OPEN,Kernel);
cv::morphologyEx(temp,Output_Image,cv::MORPH_CLOSE,Kernel);
There are many methods but there's a trade off between accuracy/speed here.
The result of above operation is:

Related

Auto transforming BufferedImage from side view/not perpendicular to perpendicular based on 4 points printed on list in Java

I see a lot of people just reading it... Maybe you need some extra info? Comment below and I'll give it!
As my previous questions were saying, I'm building a car that will orientate in the room based on an image that you would have taken with your phone. For that i would need an image that would represent the room. Since you cant take picture directly from the top of the room (unless you are a bird), I would need to transform it to a "perpendicular" image. It would be weird if you would have to do it manually so I decided to do it automatically. Now that is something harder :) Well I asked for transforming image in this thread and got that marked comment that solved part of my program. I'm still looking for a way to automate that. Since i need the image to be the same size as it would be in real life (we can take 1 pixel as 1 cm), we will probably need some kind of "points of reference" printed on an A4 paper sheet. Also, there will probably be needed some OpenCV since we will need to know the distance between two points in image. Besides that, how would you define the "correction" that has to be done based on four points?
I've done some pics for visual reference:
Id like to transform image like this:
To image like this (or even better):
EDIT: I'd like to do this in latest (3.1) version of which i have no idea about how to use it :)
EDIT #2: I've done some work on it, solving part of it in this post: Image perspective correction

Convert image to sketch and then cartoonify?

My aim is to let the user take a selfie from my app and then apply different image processing algorithms to convert it in a cartoon type image. I followed the algo written here, and then also used the method written just below the chosen answer to convert black and white sketch to colored image that should look like cartoon. Every thing is ok except that after applying Gaussian Blur , the image becomes too hazy and unclear. Here is the image output:
Any advice how I can make it more clear? Like shown in this link. I know they used Photoshop , but I want to achieve it with Java and Android.
PS: I found all the image processing methods from here. Plus the method mentioned here (the one below the chosen answer), what could be the ideal values in the arguments?
cartoonifying image
If you have a basic knowledge of C++, you can port this app for your need.
This application works real time. If you want to non-real time,than you can use bilateral filter against two medianBlurs at the bottom of function. That will give better results, but bad performance. But you need to use OpenCV in your application. If you want to make application with more functions, I will suggest you to do it.

OpenCV applying filters to specific place in image

Hello I am using OpenCV for Java and want to blur faces from image, but I keep failing to apply it only for face. How can I do it?
Your question is too general. What basically needs to be done is to run a face detection algorithm (google for face detection opencv), extract the rectangle of pixels depicting the face using cv::rect, blur them and replace the original pixels. I suggest you read about face detection (try to understand the main ideas regardless of openCV), read some tutorials on implementation and then, if you need assistance, write a more specific question here and people are sure to answer you.

How to improve the image quality before the image processing start in javacv or opencv?

I have an image with 400x400 image to identify different components from it. But when I try to identify components using that most of time it doesn't provide correct answers. So I need to know whether there are some kind of methods in javacv or opencv to improve the quality of the image or increase the size of the image without effecting to its quality ?
This is the sample image that I use. (This is the maximum size that I can get and I can't use any photo editing softwares in the project, because it's dynamically generated image.)
In my image processing I need to identify squares and rectangles that connects those squares. And specially I need to get the width and height of those using pixel values.
You can scale it to any size, if you can vectorize it... and in your case vestorization is quite simple as you have some simple geometrical objects in image.
So, in my view your approach should be like this:
detect edges in the image with a high threshold (as you have very distinct objects)
vectorize them
scale them to any size
You should also look at the following link: Increasing camera capture resolution in OpenCV.
If you stick to image processing the easiest way to do it is to apply an equalizeHist(). This will increase contrast and will improve subsequent steps.
But, and this is a biiiig 'but', why are you doing it? Just reading this post, I saw another solution, and a quick google proved me I am right:
Kabeja is a Java library for parsing, processing and converting
Autodesk's DXF format. You can use Kabeja from the CommandLine or
embed into your application. All parsed data are accessible with the
DOM-like API.
That means you can extract directly all the data you want from that image in a text format. Probably something like "at position x, y there is a transistor, or whatever." So why would you render that file into an image, then analyse that image to extract the components?
If you do it for school (I know that many school projects are like this) I would recommend you to find a real problem to solve, and propose it to your teacher. You will be happier to do something that is not complete nonsense.
vectorizing the image is best option I guess as suggested by mocap.
you can also use enhancement tools like sharpening, saturating etc.

Alpha Channel Blur

I've got this BufferedImage object that's guaranteed to contain only one color. I'm using it to display a sample image to show size, shape & hardness of a brush in a painting tool. I've tried several different blur implementations for hardness... the latest, that seems to work fairly well is this Stack Filter written by Romain Guy.
I've got 2 problems.
Faster on 1 channel than 4?: None of the blur filters I've tried seem to be quite fast enough... I realize this question has been asked before (and I'm not quite ready to try pulling in FFTW from C), but I'm wondering if there's a way to perform the blur using ONLY the alpha channel bits? The image only contains one color, so none of the other bits will change across points anyway and my thought is that this would cut the number of calculations for the blur to about 25% of the whole blur operation and I figure that's likely to result in a noticeable improvement in performance? I've not been able to find any information about this being tried via web search.
Eliminating the Dark Halo: Every time I try a different blur algorithm I end up having to rewrite it to get rid of the dark shadow around the shape caused by blurring in "black" from colorless pixels where nothing has been painted in yet. I've read about this and I'm using (as far as I know) INT_ARGB_PRE image types, which I remember reading as a solution to this problem. Am I missing something in that solution? Do I need to preformat the image in some way to make it interpret all the empty pixels as white instead of black?
Thanks!
You may find this interesting:
http://www.jhlabs.com/ip/blurring.html
The dark halo issue is discussed, all source code is available as as far as I can recall, it only uses standard Java SE stuff.

Categories