I am trying to load a small TIFF image using Emgu.CV (2.4.10). The image is a 32bit (float32) single band image, but when loading it using Emgu it opens it as a <Bgra, Single> image.
Is Emgu misinterpreting the image or are there some method to force Emgu to load the image as a <Gray, Single>?
I assume you are trying to read a image from a file. If this is the case you can simply specify the image format and bit depth when declaring the Image.
Image<Gray,Single> myImage = new Image<Gray,Single>("myFile.tiff");
Related
I have just downloaded the dataset caltech101 and I want to resize the image into the shape of (200,300,3). As I have read, I first need to convert the image into a tensor and then resize it using tf.image.decode_jpeg. But I don't know how to start from scratch with an image and turn it to a tensor.
(I'm a beginner in learning machine learning)
To load an image using TensorFlow, first decode it like so:
image = tf.image.decode_jpeg(...)
To resize it, use the image from the code above, like so:
resized_image = tf.image.resize_images(image, [299, 299])
You can find more on their API documents here.
I am trying to save an image that I generated on a Matlab Gui. I tried following code with a push button:
[Save,savename] = uiputfile('*.bmp','Save Figure As...')
fname=fullfile(savename,Save);
imwrite(handles.axes2, 'fname', 'bmp');
It doesn't work. Can anyone please help?
imwrite is for saving image data (as a matrix) to an image file. If you want to save the figure, you will want to use saveas.
If you need to save an image of a specific axes, you can use getframe to save a screenshot of the specified axes, then convert this to an image using frame2im and then use imwrite to save this image data to a file.
frame = getframe(handles.axes2);
im = frame2im(frame);
imwrite(im, fname)
I am using OpenCV 3.0 and whenever I read an image and write it back the result is a washed-out image.
code:
cv::Mat img = cv::imread("dir/frogImage.jpg",-1);
cv::imwrite("dir/result.jpg",img);
Does anyone know whats causing this?
Original:
Result:
You can try to increase the compression quality parameter as shown in OpenCV Documentation of cv::imwrite :
cv::Mat img = cv::imread("dir/frogImage.jpg",-1);
std::vector<int> compression_params;
compression_params.push_back(CV_IMWRITE_JPEG_QUALITY);
compression_params.push_back(100);
cv::imwrite("dir/result.jpg",img, compression_params);
Without specifying the compression quality manually, quality of 95% will be applied.
but 1. you don't know what jpeg compression quality your original image had (so maybe you might increase the image size) and 2. it will (afaik) still introduce additional minor artifacts, because after all it is a lossy compression method.
UPDATE your problem seems to be not because of compression artifacts but because of an image with Adobe RGB 1998 color format. OpenCV interprets the color values as they are, but instead it should scale the color values to fit the "real" RGB color space. Browser and some image viewers do apply the color format correctly, while others don't (e.g. irfanView). I used GIMP to verify. Using GIMP you can decide on startup how to interpret the color values by format, either getting your desired or your "washed out" image.
OpenCV definitely doesn't care about such things, since it's not a photo editing library, so neither on reading nor on writing, color format will be handled.
This is because you are saving the image as JPG. When doing this the OpenCV will compress the image.
try to save it as PNG or BMP and no difference will be exist.
However, the IMPORTANT QUESTION : I am loading the image as jpg and saving it as JPG. So, how there is a difference?!
Yes, this is because there is many not identical compression/decompression algorithms for JPG.
if you want to get into some details see this question:
Reading jpg file in OpenCV vs C# Bitmap
EDIT:
You can see what I mean exactly here:
auto bmp(cv::imread("c:/Testing/stack.bmp"));
cv::imwrite("c:/Testing/stack_OpenCV.jpg", bmp);
auto jpg_opencv(cv::imread("c:/Testing/stack_OpenCV.jpg"));
auto jpg_mspaint(cv::imread("c:/Testing/stack_mspaint.jpg"));
cv::imwrite("c:/Testing/stack_mspaint_opencv.jpg", jpg_mspaint);
jpg_mspaint=(cv::imread("c:/Testing/stack_mspaint_opencv.jpg"));
cv::Mat jpg_diff;
cv::absdiff(jpg_mspaint, jpg_opencv, jpg_diff);
std::cout << cv::mean(jpg_diff);
The Result:
[0.576938, 0.466718, 0.495106, 0]
As #Micha commented:
cv::Mat img = cv::imread("dir/frogImage.jpg",-1);
cv::imwrite("dir/result.bmp",img);
I was always annoyed when mspaint.exe did the same to jpeg images. Especially for the screenshots...it ruined them everytime.
I would like to be able to use the cpselect matlab tool (or a similar one) with the capability of showing both images (moving image and reference image) in RGB (I only managed to see moving image in RGB and reference image in grayscale).
Could someone point me to an alternative for this tool that would support this or anyway to be able to display both image in rgb in cpselect?
Thanks in advance.
Not sure what you're talking about, and I'm quite confused about your statement. cpselect is image independent. You can show both of them as colour or grayscale or one or the other. The example you're probably looking at is the one that comes with MATLAB: http://www.mathworks.com/help/images/ref/cpselect.html . One image is grayscale, while the other has a pinkish hue.
Here's an example showing both the source and target image as being in colour. I used onion.png that is a colour image that is part of the MATLAB system path:
im = imread('onion.png');
im_rotate = imrotate(im, 35);
cpselect(im, im_rotate);
We get:
I'm new in programming a Win32 program. I want to display a tif image in the window, but I only found ways to display bitmap image. Does anyone got idea about how to display a tif image? Thanks.
Use Gdiplus::Bitmap class to load TIFF image. Then, get HBITMAP from it by calling GetHBITMAP.