brcc32 invalid bitmap format (loosing image quality) - image

I created a delphi component and want to load an image into it at runtime.
So i created a .RC file in notepad.
useIdentifer BITMAP "demo.BMP"
When i compiled the file it gave me an error "invalid bitmap format", so I did some research and got the solution that I had to check that the file is 8-bit, so I converted it to bitmap 256 colors using paint, but due to this i lost the quality and pixels of image.
I'm not sure how can i get rid of the error without losing quality of the image.

Use a PNG image instead of a BMP. The answer to this question will tell you how.

Related

Converting TIFF to PDF with GraphicsMagick MediaBox / CropBox resolution

We are currently converting TIFF files to PDF using GraphicsMagick. The TIFF is coming from an eFAX and has a (pixel) resolution of 1728x2200.
If you do the conversion with tiff2pdf or just open it on Preview and convert export it to PDF, it is generated with a MediaBox value of 612x792 point, which is what is expected.
However graphics magick generates a MediaBox of 1728x4400 and a CropBox of 610x792. It all looks good if you open it on a PDF viewer because it's using the CropBox but if you're feeding it to GhostScript after, you don't get the Image on the full page but as a small square inside the document.
The lazy solutions would be to change for Tiff2PDF or add -dUseCropBox to our GhostScript command but I'd like to know what GraphicsMagick option should be used to have the PDF with the good MediaBox. It's like it doesn't understand that the resolution is in Pixels and not in Point. Hope somebody has insights

Dicom image not converting with dcmtk

The image http://www.barre.nom.fr/medical/samples/files/MR-MONO2-16-head.gz on http://www.barre.nom.fr/medical/samples/is not converting to other image formats. I tried following commands (after extracting the dicom file):
dcm2pnm --write-png MR-MONO2-16-head out.png
dcm2pnm +obr MR-MONO2-16-head out.bmp
dcm2pnm MR-MONO2-16-head out.pnm
It also did not work with dcmj2pnm and dcml2pnm. All of them just produce a gray box. The image otherwise is OK and is correctly read by proper dicom viewer softwares. Where is the problem and how can it be solved?
The problem is that no windowing settings are present in the header. You need to instruct dcm2pnm to calculate a window from the histogram (+Wm) or specify windowing values to apply.
dcm2pnm +Wm +obr MR-MONO2-16-head MR-MONO2-16-head.bmp
yields a bitmap image that looks fine to me.

MATLAB imread() can't read old images?

So I ran into a weird problem with the MATLAB imread() function where it can't read old images (in this case, a bmp from 2002). Basically when I pass the image as an argument to imread(), it recognises the image as a grayscale even though it is clearly RGB.
Image is part of a standard test set available to download from here. I am using the 'boy.bmp' image.
% In Downloads folder
I_dl = imread('boy.bmp');
whos %to show current variables
OUTPUT:
Name Size Bytes Class Attributes
I_dl 512x768 393216 uint8
The image size is actually around 390KB so it's not that only one channel is getting loaded into the workspace somehow. Looks like it has to do with some older encoding system.
I ran an imshow() to check the image and this was the result.
TEMPORARY WORK-AROUND: I imported the image into GIMP, saved it as an xcf (GIMP's native format) and then exported it as a bmp. Then I did the imread() and then whos. It works.
Name Size Bytes Class Attributes
I 512x768x3 1179648 uint8
The file size expanded to 1.2MB too. Strange.
Any one else faced the same issue?
Regards.
boy.bmp contains the indexed image. You should load and use the colormap matrix:
[I_dl,cmap] = imread('boy.bmp');
imshow(I_dl,cmap);

OpenCV imwrite gives washed-out result for jpeg images

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.

Issue when changing dpi of a tiff using Bit Miracle libtiff

I am trying to just change the resolution of a tiff image using Bit Miracle libtiff. Below is the code snippet. When I do this, tiff image resolution is changed, but the other tiff parameters are gone and I am unable to open the tiff file. Could you please help if I am doing something wrong here?
using (Tiff image = Tiff.Open(fileName, "a"))
{
image.SetField(TiffTag.XRESOLUTION, 200);
image.SetField(TiffTag.YRESOLUTION, 300);
image.WriteDirectory();
}
Please note that changing TiffTag.XRESOLUTION or TiffTag.YRESOLUTION won't change image data and will only change the way the data is interpreted by viewers or printers.
As for the code itself, you should:
Call SetDirectory(0) before calling SetField methods. That's because you open file in append mode.
Use RewriteDirectory instead of WriteDirectory. Otherwise you might corrupt image data.

Resources