My original image sizes is 841x482 pixels.
First step, I need to rescale these image because of my original image does not enough to crop into 512x512 pixels.
Secondly, after rescale these image, I want to crop the image into 512x512 pixels, and feed it as my input image.
How can I rescale these image? Anyone can help? Thanks. My example image as below:-

 Akzeptierte Antwort

Walter Roberson
Walter Roberson am 30 Jul. 2023

0 Stimmen

You can imresize -- but you have to decide whether you want to resize directly to 512 x 512 (which will change the aspect ratio of the pixels), or if you want to resize to 841 x 512 (stretch in one direction) or to some other size such as doubling the size in each direction.
After you have resized to at least 841 x 512 then you can use imcrop() passing in the image array and the crop position and size.
You have not been clear as to what part you would like to crop out. Cropping out the dark part to the right would seem most plausible. But you might also be thinking of cropping out the words. Or perhaps you are thinking about cropping out random patches?

6 Kommentare

Hello Sir, thanks for your answer. In my case, I want rescale at first place from original image sizes of (841x481) to 841x841pixels. After that, I will crop the suspicious area which is the lesion (will crop 512x512pixels). Since the lesion can be anywhere in the tissue area, so I will crop the image data using center crop at the center of the lesion and adjust abit and exclude the dark part in my cropping area. Is rescale and resize is the same codes Sir? What is the different these two options?
crop_size = [512 512];
enlarged_image = imresize(Original_image, [841 841]);
enlarged_size = size(enlarged_image);
offset_to_start_crop = floor((enlarged_size(1:2) - crop_size)/2);
cropped_image = imcrop(enlarged_image, offset_to_start_crop);
Changing the size of an image is sometimes called rescaling it, so it is entirely understandable that you might be confused between resizing and rescaling.
It happens that MATLAB uses imresize to refer to the process of interpolating an image from one size to a different size, and that MATLAB uses rescale to refer to leaving an array the same size but doing a linear interpolation of the value representation.
For example if you had an image that uses 8 bit integer representation, values 0 to 255, then you can create an image with the same size and same information by taking double(The8BitImage)/256 getting out double precision 0/256 to 255/256 (in increments of 1/256) . MATLAB would call that "rescaling" the data.
There are a number of situations in which it is useful to map the lowest value present in an array to 0, and to map the highest value in the array to 1, and to map the other values in the array as a linear fraction within that 0 to 1 range. To MATLAB, that is "rescaling" the array.
Other programs might use different wordings. "resize" an image almost always refers to getting out an image that is a different size, but "rescaling" an array might mean that as well, depending on the program.
Okay Sir, now I get what you explained these two diferences.
But I prefer to do rescale than resize because I need an image with same information on it to feed my input data into neural netwrok later on. Just need to rescale the image into bigger than original sizes without any changing information in the image.
So, as I want to rescale the image, I have tried to write this code:-
a=imread('L RA 7200001.jpg');
X = a(1:3);
R = rescale(X);
Let say I want to rescale about 0.25 bigger than orignal sizes, is this code correct?
Walter Roberson
Walter Roberson am 1 Aug. 2023

You would have to write your own routine named rescale() to do that, and if you did then the routine would cause conflicts with the existing matlab rescale()

MATLAB rescale() function always leaves the array the same size, and changes the value representation to a different range, such as converting integer 10000 to 24000 to be the range 0 to 1 (for use in processing CT Scan)

Whether matlab is "right" or "wrong" to call changing the size of an image as "resizing" instead of "rescaling" does not matter at the moment: it does use imresize() for changing image size, and it does use rescale() for changing value scaling factors linearly without changing the size of the array, and you just have to work with that.

I already posted the code to change the size of the image and then center-crop the result.

Hello Sir. I have tried imsize codes. As you mentioned above, if using imresize() for changing image size, I want to ask, does it changing the size of the array if I using imresize()? As you can see image below, I have tried these codes. After resize it, the image resize looks like abit blurry (not distinct). Here's my codes:
>> I=imread('L RA 7200001.jpg');
>> imshow(I)
>> magnificationFactor = 1.25;
>> J = imresize(I,magnificationFactor);
>> imshowpair(I,J,method="montage")
>> imwrite(J,'xL RA 7200001.jpg');
filename = 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/1445537/image.jpeg';
I = imread(filename);
magnificationFactor = 1.25;
J = imresize(I,magnificationFactor);
size(I)
ans = 1×3
482 841 3
size(J)
ans = 1×3
603 1052 3
size(J) ./ size(I)
ans = 1×3
1.2510 1.2509 1.0000
You can see that J is indeed larger than I by approximately the magnification factor.
After resize it, the image resize looks like abit blurry
That is not uncommon, especially when you are starting with JPEG images.
The standard JPEG compression loses information, especially on vertical and near-vertical edges. In order to reduce the visual impression of what it is doing, it does "aliasing" -- fills in fake information along slopes that blend in the edges. Those changes are not easy to see visually when working with an image the original size, but the changes make it difficult to do scientific analysis of images that have undergone JPEG compression. The effects of JPEG compression become more noticable when you resize JPEG images.
But besides that, when you resize images, the resizing algorithm cannot increase the information content of the image. When you ask to resize an image to 25% larger, the effect is not the same as-if you had had a camera with a higher resolution. Instead, the resizing algorithm more or less has to take 4 adjacent pixels and "smear" them into 5 pixels. The result will, in most cases, be less sharp than the original.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Convert Image Type finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by