How to increase the size of an image
조회 수: 13 (최근 30일)
이전 댓글 표시
I have an image which is 256x256 double. I want to increase the image size to 800x1280 double. I tried to use the imresize function:
b = imresize(a, [800 1280]);
But with this method the image resolution changes, if I'm not mistaken. Is there a way to increase the image size, but don't change the image resolution ?
댓글 수: 0
채택된 답변
Walter Roberson
2019년 1월 14일
But with this method the image resolution changes, if I'm not mistaken.
You are mistaken. imresize() does not invent information, just interpolates it.
Resolution is information density. When you resize to larger, you copy the information out over more locations, leading to the same total amount of information.
My guess is that you have a real-world pixel resolution in mind, and want to write out an image file that maps the overall image size to the same physical distance.
Most images you read in will not have a meaningful physical size attached to them (at least not in the image itself.)
PNG files can have an XResolution and YResolution that you can look at using imfinfo(), and imwrite() permits you to pass XResolution and YResolution parameters to be written into the files.
JPG files might have the semi-standard of having EXIF information stored in them, and the EXIF might happen to contain physical resolution information. When present it can be extracted on input by using imfinfo() and knowing which field to look at and parse. MATLAB does not offer any way to write EXIF information, but there is a File Exchange contribution for use with Windows that runs an external executable that can write EXIF to a file.
TIFF has tags that you can store fairly arbitrary information, but does not itself define any particular tag for this purpose. GeoTIFF defines particular tags for use with TIFF that can be used for geographic information and mapping purposes including specifying resolution in various ways: it would be better to use GeoTIFF than to invent your own tags. In theory you could even write an EXIF block as a TIFF tag.
DICOM has very meaningful resolution parameters that you can read in and write out; the exact attribute to use for DICOM depends upon the modality (and sometimes on context within the modality.)
Warning: MOST resolution information that you read in from PNG or EXIF is wrong. MOST programs just slam an arbitrary 72 or 100 (pixels per inch) in place. Including, regretably, a lot of cameras, including cameras used in lower price scientific instruments.
Some of the "prosumer" cameras do try to write in meaningful information, including by using the current autofocus distance and the aperature information and the sensor size in order to figure out how large a sensor pixel corresponds to in the real world.
댓글 수: 0
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!