Resizing command changes image shape - matlab

I have to resize image i.e if its dimension is 3456x5184 to 700X700 as my code needs image with less number of pixels otherwise it takes too much time to give results.So, when I use imresize command it changes the dimensions of image but at the same time it changes the shape of image i.e the circle in image which I also need to detect looks like oval instead of being cirle. I need your suggestions to resolve this problem. I am really grateful to you people.

Resizing images is done by either subsampling (to get smaller images) or some kind of interpolation (to get larger images)
Input is either a factor or a final dimension for width and height.
The only way to fit a rectangle into a square by simply resizing it is to use different scales for width and height. Which of course will yield in a distorted image.
To achieve what you want you can either crop a 700x700 region from your image or resize image using the same factor for with and height. Then you can fit the larger dimension into 700 and fill the rest around the other dimension with black or whatever you prefer.

Related

Advanced image scaling in JasperReports

I need to include many images of unknown origin in a report. I have no idea what the images might be: portrait or landscape fotos, large or small, or even something with an atypical shape, like a 400x80 logo.
I'd like to scale down images with the following rule: proportionally downscale until the larger side is 200. And resulting image shouldn't take more space than needed (i.e. 1000x600 should be downscaled to 200x120, not to 200x200), so that there are no unneeded blank margins around non-square images.
Is what I need possible with JasperReports?
EDIT:
To clarify: "real size" mode is almost what I need. However, I don't see a way to limit height of resulting image. As a result, if the image I want to print is a portrait foto (or has even larger height compared to width), generated PDF looks ugly; in this case I would prefer to somehow downscale it to a smaller width.
I solved the Problem of resizing images of various sizes to a fixed size with "RetainShape" by writing an ImageResizer, based on the idea of the ImageTransformer from https://stackoverflow.com/a/39320863/8957103 , using https://github.com/rkalla/imgscalr for scaling the image.

How to auto-crop a barrel-distorted image using ImageMagick?

Using ImageMagick's convert to barrel-distort a photo to correct a strongly visible pincushion distortion, I provide positive a, b or c values (from a database for my lens + focal length). This results in an image that is corrected, has the original width and height, but includes a non-rectangular, bent/distorted border, as the image is corrected towards its center. Simplified example:
convert rose: -virtual-pixel black -distort Barrel '+0.0 +0.1 +0.0' out.png
How can I automatically crop the black, bent border to the largest possible rectangle in the original aspect ratio within the rose?
The ImageMagick website says, that a parameter "d" is automatically calculated, that could do this (resulting in linear distortion effectively zooming into the image and pushing the bent border right outside the image bounds), but the imagemagick-calculated value seems to aim for something different (v6.6.9 on ubuntu 12.04). If I guess and manually specify a "d", I can get the intended result:
convert rose: -virtual-pixel black -distort Barrel '+0.0 +0.1 +0.0 +0.6' out.png
The given formular a+b+c+d=1 does not seem to be a proper d for my cropping case. Also, d seems to depend on the aspect ratio of the image and not only on a/b/c. How do I make ImageMagick crop the image, or, how to I calculate a proper d?
Update
I found Fred's ImageMagick script innercrop (http://www.fmwconcepts.com/imagemagick/innercrop/index.php) that does a bit what I need, but has drawbacks and is no solution for me. It asumes arbitrary outer areas, so it takes long to find the cropping rectangle. It does not work within Unix pipes, and it does not keep the original aspect ratio.
Update 2
Contemplating on the problem makes me think that calculating a "d" is not the solution, as changing d introduces more or less bending and seems to do more than just zoom. The d=1-(a+b+c) that is calculated by imagemagick results in the bent image touching the upper/lower bounds (for landscape images) or the left/right bounds (for portrait images). So I think the proper solution would be to calculate where one of the new 4 corners will be given a/b/c/d, and then crop to those new corners.
The way I understand the docs, you do not use commas to separate the parameters for the barrel-distort operator.
Here is an example image, alongside the output of the two commands you gave:
convert o.png -virtual-pixel black -distort Barrel '+0.0 +0.1 +0.0' out0.png
convert o.png -virtual-pixel black -distort Barrel '+0.0 +0.1 +0.0 +0.6' out1.png
I created the example image in order to better visualize what you possibly want to achieve.
However, I do not see the point you stated about the automatically calculated parameter 'd', and I do not see the effect you stated about using 'd=+0.6'...
I'm not sure I understand your wanted result correctly, so I'm assuming you want the area marked by the yellow rectangle cropped.
The image on the left is out0.png as created by the first command above.
In order to guess the required coordinates, we have to determine the image dimensions first:
identify out0.png
out0.png PNG 700x700 700x700+0+0 8-bit sRGB 36KB 0.000u 0:00.000
The image in the center is marked up with the white rectangle. The rectangle is there so you can look at it and tell me if that is the region you want cropped. The image on the right is the cropped image (without scaling it back to the original size).
Is this what you want? If yes, I can possibly update the answer in order to automatically determine the required coordinates of the cropping. (For now I've done it based on guessing.)
Update
I think you may have mis-understood the purpose of the barrel-distortion operation. It is meant for correcting a barrel (slight) distortion, as is produced by camera lenses. The 3 parameters a, b and c to be used for any specific combination of camera, lens and current zoom could possibly be stated in your photo's EXIF data. The formula were a+b+c+d = 1 is meant to be used when the new, distortion-corrected image should have the same dimensions as the original (distorted) image.
So to imitate the barrel-correction, we should probably use the second image from the last row above as our input:
convert out3.png -virtual-pixel gray -distort barrel '0 -0.2 0' corrected.png
Result:

MATLAB: How do I resize (connected) components in a 3D binary image sequence without changing the dimensions of the sequence?

I'd like to resize the components contained in a 3D binary image sequence without changing any of the dimensions of the sequence itself.
I'm not sure if I need to do it on a component-by-component basis, if yes, then how do I create a transform such that the resized components are re-positioned 'correctly' in the image sequence? By 'correctly', I mean with the same centre of mass as the original unprocessed components.
(If that last paragraph doesn't make sense then please ignore)
A 2D example: suppose I wanted to enlarge by 10% the white blobs in the following [295x445] image
How would you do this without making the image itself larger?
you could use the imdilate function to dilate the regions of interest. The examples in the webpage show how to use this function.

Scaling while conserving ration

Upon using the convert method, I would like to be able to transform a landscape or portrait image given the height and width specify without altering the ratio.
From the documentation, the 'clip' options act as follow:
'clip': Resizes the image to fit within the specified parameters without distorting, cropping, or changing the aspect ratio
If I have a 200x50 image and I want a 150x150 result, this would result in a 150x37px resized image with its ratio identical to the original's.
If I have a 100x50 image and I want a 150x150 result, this would result in a 150x75px resized image with its ratio identical to the original's.
'crop': Resizes the image to fit the specified parameters exactly by removing any parts of the image that don't fit within the
boundaries
If I have a 200x50 image and I want a 150x150 result, this would result in a 150x37px cropped image.
'scale': Resizes the image to fit the specified parameters exactly by scaling the image to the desired size
If I have a 200x50 image and I want a 150x150 result, this would result in a 150x150px resized image where the ratio has been altered to fit.
'max': Resizes the image to fit within the parameters, but as opposed to 'clip' will not scale the image if the image is smaller
than the output size
Same output as in 'clip' except that if I have a 100x50 image and I want a 150x150 result, this would result in a 100x50px resized image with its ratio identical to the original's.
What I would like to have is the ability to make an image conserve its ratio and be of the required dimension (with vertical and horizontal centering if need be). It would result in an image that is not distorted nor clipped.
I understand there are some trickiness to the task as you have to determine what color do you fill the space with (see ImageMagick doc about space filling).
Any insight would be great, hope it is not too much of an edge case.
Take a look at this set of examples in the ImageMagick documentation:
http://www.imagemagick.org/Usage/thumbnails/#square
We don't currently offer the ability to "fill" empty parts of the image with a background color, so do not support this use case. We are looking at adding it in the near term, and will update you when this is added.

Difference between stretching and scaling an image

Can anybody please tell me what is the exact difference between stretching and scaling an image? Because you can anyway set the size of image and imageView both to match your requirements.
It depends on how you define stretching, but I would divide scaling into two distinct options based on whether or not the aspect ratio is preserved. Often it is desired to preserve the aspect ratio when scaling an image.
I would consider an increase in one dimension, but not proportionally in the other to be a "stretch". Similarly, a decrease in one dimension, but not proportionally in the other would be a "squash".
You may find this Daring Fireball post interesting.
Stretching sounds like showing small size (10x10) image at (100x100) or (100x10). so some times it gets pix-elated.
And scaling means to show a image to different size either small or big with maintaining its aspect ratio (programmetically), so it will look not improper, because when you stretch to different aspect ratio then some objects in image gets improper visibility.
Stretching (in iphone IB) means '9-slice scaling', scaling means just scaling.
When stretching you can determine which part of the image may be used for stretching and which part may not. For example when you have a rounded square, you do not want the roundings to stretch, especially when you're only stretching horizontally or vertically.
You indicate that you only want to use the middle pixel to stretch by (in IB) setting the X & Y values to 0.50 (half way) and the width & height values to 0.00 (minimum amount of pixels)
Lookup contentStretch in the docs for more info
when you don,t keep the congruence of your image, you see the image incongruous and height and width of your image is not suitable for showing. for resolving this issue you can multiply your image's width and height to to a constant coefficient.
Stretching and scaling don't mean anything different except maybe in connotation.
Is there a particular piece of text somewhere that you are trying to understand? Maybe we can help with that.
stretching image is stretching the size of a small image.
on the other hand scaling of image is scaling the image accoring the the viewport's width and viewport's height....
scaling can be done by small as well as large image.
you should take a good quality image and then should scale it
sprite.setscale(x,y);