Resize images Matlab - matlab

I want to resize images, but it should keep the height/width ratio when doing the resizing. What I do is, first I check whether which side (width or height) is the long. If the width is long, I'll give 150 to the width's size and resize the height without affecting to the shape of the image and vise versa. I am talking this resized image for a edge detection algorithm and output binary image is sent to the neural network which requires constant number of inputs. In this case, one side of (width or height) the image is 150 and other side is less than 150(vary from image to image). But I want to add black color to the other side(less than 150) until its size is 150. So, I can sent 150*150 inputs to the neural network.
Question is How can I add black color to the other side(less than 150) until its size is 150?
Thanks in advance

http://www.mathworks.com/help/toolbox/images/ref/imresize.html
http://www.mathworks.com/help/toolbox/images/ref/padarray.html
newim = imresize(im, 150 / max(size(im));
paddedim = padarray(newim, size(newim) - 150, 0);

Creates an matrix of zeros. Calculate the position of the top-left pixel. Then copy your image to that matrix slicing from the top-left pixel.

Related

How to find height of the specific point in this OCT image?

I am a beginner in Matlab who is working on medical image processing of retinal OCT images. My aim is to align all the images to 1 height value. I want to find the maximum height of the layer in the eye.
For example, if input :
the output: returns this height:
I have tried this approach as outlined in Hand_height but it returns the height of the complete image.
Iterate over X and find the first peak (blue point) using findpeaks in the vertical direction (Y) to generate the first layer (blue line),
and then determine the peak with the smallest index in the Y-direction.
Please see the image!
In order to find maximum high you should find the top border of a retina.Here you have an example of how to find it.

Resizing command changes image shape

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.

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.

CGAffineTransformScale scales imageview,but its sub elements on redrawing got blurred

I am simply using this code to transform imageView to scale double or triple.
imageView.transform = CGAffineTransformScale(CGAffineTransformIdentity, scale, scale);
I am drawing lines on this imageView in drawRect,after scaling everything got scaled. What i want is those lines which i am drawing should remain of same size or width after scaling.In order to do that ,i am redrawing lines on scaled imageView with proportional less height and width but result is like lines got blurred/shady.I think on transforming the pixels size also got increase of imageView..I want to know is there any way to draw proper lines without any blurred effect on transformed imageView etc..
Draw the lines AFTER you scale the image. Just change the width of the line to be the same scale (ie image is 4x, line width is 4x).

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);