I currently have a binary black and white image that I have used cvThreshold on, and I would like to get the color back on the white part of the image.
From my understanding multiplying the original image with the binary image will result in this effect. I am however unsure how to do that. I am using JavaCV. Ive attempted to:
IplImage img.mul(im2);
And that hasn't really worked. How do I use the mul openCV function with JavaCV? Also if anyone has tips on generally converting opencv code to JavaCV I would be very grateful, the little there is on the JavaCV project page is barely enough to keep me afloat.
I have my own (maybe quite strange :)..) way to find functions working in JavaCV, but in many cases it works. There's OpenCV's wrapper for C# named emguCV , which have very similar functions to this in JavaCV. So if I want e.g find multiplying or adding function I write in google: cvMul emgu or something similar,and here is result of my searching:
Wiki emgu link 1
Wiki emgu link 2
So If you want to multiply 2 IplImages you could do something like that:
IplImage Red=IplImage.create(zdj1.cvSize(),8,1);
IplImage Green=IplImage.create(zdj1.cvSize(),8,1);
IplImage Result=IplImage.create(zdj1.cvSize(),8,1);
cvMul(Red,Green,Result,1);
Related
Preferably, I'd like to use an array, iterating over each pixel and setting the R G B values.
And I don't think that I can use HTML canvas in any way. I'm hoping to build it right on top of a Google Doc without additional libraries or references to external websites.
Everything I have found on the Image Class, type is about positioning or resizing, but not helpful for stating the image.
ImageItem .setImage() looks promising, but is not particularly descriptive.
You can implement your own encoding algorithm (or migrate someone else's) and transform your pixels array into an image blob compatible with the ImageItem.setImage() method.
I'm using the print function in MATLAB to write images of plots, something like that
print(figure(1),'-dpng','-r300',filename);
But apparently the images are not overwritten, and the original images stay. I was using saveas before, which seems to overwrite the images, but print gives me more output options. Any ideas?
UPDATE: I ended up deleting the files before the printing with a different function.
You can use this:
im = frame2im(getframe(gcf,rec)); %Grabs image of plot as an image
imsave(im, filename); %save image
That syntax may not be 100%, its a while since I've used it.
Also be aware that this isn't perfect - I remember having issues with it grabbing a grey border around the edge of the plot. Also, I think the image may be based on a matlab screenshot.... just something to be aware of
Saving figures in matlab is rather troublesome, especially if the saved image should look like the original figure.
For myself i found the solution in using export_fig.
It's one of the most downloaded fileexchange files - maybe you should give it a try:
http://www.mathworks.de/matlabcentral/fileexchange/23629-export-fig
A small introduction to export_fig can be found at:
https://github.com/ojwoodford/export_fig/blob/master/README.md
can anyone help me to save my resulted images by using imwrite
source = 'C:\Y\';
im_number=5;
for i=1:5
image{i}=im2double(imread([source,'Carbon_', num2str(i)],'tif'));
image{i}=double(image{i});
B{i}= Sftfun(image{i});
B{i}=uint32(B{i});
imwrite(B{i},[source,'face_', num2str(i)],'tif');
end
The problem with your code is that you are casting your image to uint32. If you are trying to save your image as a TIF file, you can only save it as 8-bit or 16-bit. Consulting the MATLAB documentation, you can only save with these two bit depths. 32-bit depths are not supported.
Consult the MATLAB documentation for more details: http://www.mathworks.com/help/matlab/ref/imwrite.html
As such, either cast the image as 8-bit or 16-bit (through im2uint8 or im2uint16), or normalize your image so that it goes from [0,1] (through im2double).
I also have some comments about your code that do need fixing for readability:
Do not save your images to a cell array called image. MATLAB has a built-in command called image which takes in a matrix and displays it to the screen for you as an image. Bear in mind this is not the same as imshow. By doing this assignment, you will shadow over the actual image command, and so any scripts that rely on this function will result in an error.
im_number seems to be an unused variable. I'm not sure what its purpose is, but I'd say it's safe to remove this statement as well.
Get rid of the following statement as you are already converting the image to a double type in the previous line:
image{i} = double(image{i});
Aside
It seems that you have asked a similar question here: save tif 32 bit images by using imwrite
This question has already been resolved in that you are not able to save 32-bit images using imwrite. However, someone in this thread has posted a workaround for you to use in MATLAB. Try using that instead of imwrite.
Is it possible to have enaml as target for OpenCV?
I'm thinking how to setup GUI and what to use.
Nothing too complicated, I need to be able to set some bitmap background, draw rectangles and circles over it, but also have the possibility to select/move these graphics objects.
Also, I would like that I do not have to take care of all these elements when I stretch the window, etc. they should do this automatically since they would be defined in some "absolute" space. I think I could easily make it work for the bitmaps (even from memory), by overriding request_image in ImageProvider object (even though I see some strange cache happening in provider/enaml view).
Problem that I'm having now with OpenCV (OSX 64) is that even when I get resize to work with qt backend and CV_WINDOW_NORMAL, the content does not stretch.
I like OpenCV, because easily I get basic UI functions.
On the other hand I started to like enaml so I'm thinking did anyone manage to get these to to work together.
I'm thinking if link with MPL works, it's possible that coupling with OpenCV should be possible :)
Thanks!
If you can get your image into argb32 or png format, you can use an Enaml ImageView to display it.
Take a look at the ImageView example:
https://github.com/nucleic/enaml/blob/master/examples/widgets/image_view.enaml
This should do it:
from enaml.image import Image
from cv2 import imread, imencode
open_cv_image = imread('./cat.png')
png_image = imencode('.png', open_cv_image)[1].tostring()
enaml_image = Image(data=png_image)
Is it possible to simultaneously display an image and the pixel,coordinate values based on the mouse pointer positions?
I am asking an OpenCV equivalent of imview function in MATLAB.
You don't need Qt to do that. Just use default OpenCV function imshow to show image and SetMouseCallback to set callback on mouse click.
It can be done using mouse call back events. You can find a good example in \opencv\samples\cpp\grabcut.cpp
I had a few problems trying to do this with OpenCV alone using an old code I wrote a while back. At this point I'm not sure if I missed something or if it's a bug in OpenCV. I'll investigate this further.
But I shared a short, self contained, correct (compilable), example at my repository, check cvImage. It's written in C++ with Qt and OpenCV. It's a Qt application that loads an image with OpenCV and displays the RGB values as the title of the Qt window.
Move the mouse around and place the cursor on top of the pixel that you are interested at to see it's RGB value.
Opencv with Qt support will do that.