How to convert .png to bitmap (.bmp) in MATLAB? - matlab

I am having difficulties converting a png file of simple black-coloured patterns I made using Illustrator into a bitmap. I need to do this in order to 3D print it (vector printer).
I was instructed to use MATLAB to do it however I tried using imread and imwrite but I'm rather confused as to what the first argument of imwrite, A, should be? Is there a particular format I need to use for it to work?
I tried doing it with an online converter and it gave me the same exact image but of type .bmp. Is that what's meant to happen?
I would appreciate any insight on the problem.

Use imread to read your png, then imwrite to save it in bmp format.
Implementation:
pic = imread('mypic.png');
imwrite(pic,'mypic.bmp','bmp');

Related

How to load DICOM pixel data in browser preserving HU values?

I need to display the DICOM images in a browser. This requires, the DICOM to be converted to PNG (or any other compatible) format.
I also need to calculate some overlay pixels based on dynamic input from the user. On conversion to PNG, I am getting 4 values (Alpha, R, G, B). But I can not use these values for my calculations. I need the original HU values from the DICOM images.
Is there any way that, PNG can contain the original DICOM values. I heard that using monochromatic 16 bit PNG format it is possible. How do we do that?
Alternatively, how to load DICOM pixel data in browser preserving HU values?
When you convert DICOM pixel data to other non-DICOM format like PNG, BMP, JPG, J2K etc., the data you are looking for is lost. You may further research for TIF format whether it preserves the data and it loads in browser. I guess it will not.
I will recommend to avoid this way. Instead, I will suggest using DICOM pixel data as-is in browser. This can be achieved by involving some java-script DICOM toolkit for browsers like cornerstone. You may also look for other toolkit if available and suits you.
Note that this involves learning curve. It will be too broad here to explain its working.

Load PDF Image into MATLAB

I have a PDF of building schematics. I would like to load it into MATLAB, and visualize the image via a GUI, so I can measure distances and such for some calculations.
I have no idea if this is even possible?
Furthermore, the PDF has an embedded scale (i.e. 1 cm = 1 meter). If I can extract this as well, that would be awesome.
I found extractFileText which can be used to extract text, but not much else.
I found the easiest way to do this was to convert the pdf to a image, for example using imagemagick. See this question
If you add an example of the image someone might be able to suggest some ideas for extracting the scale information using image processing.

Convert tiff to dicom using Matlab

I have a series of dicom images and did change the HUs in the images using MATLAB scripts, then I imported them in ImageJ for display. Then I realised I can modify the images using ImageJ gui (which much easier, just moving the mouse). However, when I saved the modified images in ImageJ, they were saved in tiff format.
My question is that, is there a way to save images in imageJ as dicom format ?
or is there away to convert tiff format to dicom using MATLAB ?
Any suggestion ?
You can convert tiff format to dicom with dicomwrite:
dicomwrite( imread('input_image.tif'), 'output_image.dcm')
The following plugins allow writing DICOM files directly from ImageJ:
DICOM Import and Export plugins
The Tudor DICOM Tools

pixel values changing after doing imwrite in MATLAB

The imwrite function is behaving in a weird way. I have modified a single pixel value of an image. After performing imwrite, however, the pixel value is either getting changed to a entirely new value OR is remaining unchanged.
function imwriteCheck(input_image,output_image)
a=imread(input_image);
fprintf('\nBefore modification a(1,1,1)=%d\n',a(1,1,1));
a(1,1,1)=50;
fprintf('\nAfter modification a(1,1,1)=%d\n',a(1,1,1));
imwrite(a,output_image);
b=imread(output_image);
fprintf('\nValue at b(1,1,1)=%d\n',b(1,1,1));
end
I've tested this function with two images and the outputs are as follows:
>> imwriteCheck('MOM.jpg','MOMout.jpg')
Before modification a(1,1,1)=206
After modification a(1,1,1)=50
Value at b(1,1,1)=170
>> imwriteCheck('durga.jpg','durgaout.jpg')
Before modification a(1,1,1)=63
After modification a(1,1,1)=50
Value at b(1,1,1)=63
I cannot understand why this is happening. Thank you for your help.
if you write to a jpg file, pixel values get changed because of their lossy compression technique. you can write to a jpg file using lossless mode but then you wont be able to view the image anywhere else.
try writing to a bmp or png file, you'll see the pixel values are NOT changing.

improving resolution of jpeg images in matlab

I have a jpeg which has reasonable resolution. I am looking for a method of improving the resolution of the image and then exporting it into a pdf file.
Currently I have imported the jpeg:
Img = imread('F:Work\fig.jpg');
From here I was hoping of exporting the figure by using the export_fig function:
https://sites.google.com/site/oliverwoodford/software/export_fig
But I am struggling on generating the figure which is required prior to exporting the image.
What part of the figure creation process are you struggling with? The general approach I would use is
Img = imread('F:Work\fig.jpg');
bigImg = imresize(Img,2);
imshow(bigImg);
export_fig test.png -native;
Check Matlab's documentation for different interpolation options that can be used when resizing images.