Hi, there i want to crop and save images 7x7 from a folder the fullname of the folder is c:\users\michaela\Desktop\homework\2 can anyone help me with the code in matlab .I want to take a different picture it's time and crop it and this i want it for 10.000 times .How can i achive that?

5 Kommentare

Walter Roberson
Walter Roberson am 16 Mai 2021
You want to save as 7 pixels by 7 pixels ??
Which portion of the image do you want to extract out?
Is it possible that you want to resize to 7 x 7 instead of cropping to 7 x 7 ?
mixaela pozoukidou
mixaela pozoukidou am 16 Mai 2021
For example i want the code to select an image from the folder cropping size 7x7 not resizing and save it . But i want different images at each time
mixaela pozoukidou
mixaela pozoukidou am 16 Mai 2021
Im not interested at portion of the image but i want the size to be 7x7
Image Analyst
Image Analyst am 7 Aug. 2021
Bearbeitet: Image Analyst am 7 Aug. 2021
So, just to be clear, let's say you have a folder with 500 images, and each image is 1920x1080 pixels. So you are "not interested at portion of the image" which I take to mean that you want to extract out a 7x7 patch from somewhere, but don't care where. From some random location, I guess. So you want to extract a 7x7 chunk of the image from a random location in the 1920x1080 image. In the end you will have 500 7x7 "images" -- is that correct?
By the way, what good are 7x7 images? Nothing in them will be recognizable.
Walter Roberson
Walter Roberson am 8 Aug. 2021
One of the reasons people take random small samples from an array is if they are doing Compressive Sensing -- though for that particular application you would usually want to know where you extracted the patch from.

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Walter Roberson
Walter Roberson am 16 Mai 2021

1 Stimme

projectdir = 'c:\users\michaela\Desktop\homework\2'
outdir = 'c:\users\michaela\Desktop\homework\2\cropped';
outsize = 7;
if ~exist(outdir, 'dir'); mkdir(outdir); end
ext = '.jpg'; %adjust as appropriate
dinfo = dir( fullfile( projectdir, ['*' ext]));
filenames = fullfile {dinfo.folder}, {dinfo.name} );
for K = 1 : length(filenames)
thisfile = filenames{K};
[~, fname, fext] = fileparts(thisfile);
outfile = fullfile( outdir, [fname fext]) );
thisimg = imread(thisfile);
[r, c, p] = size(thisimg);
rc = randi([1 r-outsize+1]);
cc = randi([1 c-outsize+1]);
cropped = thisimg(rc:rc+outsize-1, cc:cc+outsize-1, :);
imwrite(cropped, outfile);
end
This crops a random 7 x 7 section out of the image and saves the result into the directory indicated by outdir
We know that you want a random portion cropped out because you did not answer the question about which part of the image should be selected, so that tells us that you do not care which part as long as it is 7 x 7.

11 Kommentare

mixaela pozoukidou
mixaela pozoukidou am 16 Mai 2021
Thank you very much i will try this and if i had a problem can i ask you for more information?
mixaela pozoukidou
mixaela pozoukidou am 16 Mai 2021
Thank you very much for your time it works
mixaela pozoukidou
mixaela pozoukidou am 7 Aug. 2021
there is a case to know that I can deform a patch of image?
Walter Roberson
Walter Roberson am 7 Aug. 2021
How would you like to deform it?
mixaela pozoukidou
mixaela pozoukidou am 7 Aug. 2021
I have work that I do logically it will write the way but because I have not understood yet give me a day to find what it means and I will answer you.
mixaela pozoukidou
mixaela pozoukidou am 8 Aug. 2021
The distortion model is given by equation 2. Essentially it says that a patch can change in space (warp) ie the pixels change positions (function φ), but also in color / intensity (contrast a and mean b). The following formulas explain how all of this is calculated. if you want i can send you ak email i have the equations but i dont know how to calculated.
mixaela pozoukidou
mixaela pozoukidou am 8 Aug. 2021
Can i send you the paper to see the equations maybe you can help me
Walter Roberson
Walter Roberson am 8 Aug. 2021
You could post an image of the equations here.
mixaela pozoukidou
mixaela pozoukidou am 8 Aug. 2021
In 3.1.1 describe the deformation model i think that all the equations are needed
mixaela pozoukidou
mixaela pozoukidou am 11 Aug. 2021
did you have any opportunity to see the equations?
Walter Roberson
Walter Roberson am 11 Aug. 2021
This does not appear to have anything to do with the Question about cropping and saving; you should start a new Question, and you should be more specific about what assistance you are asking for.
It is not likely that I myself will have the resources to program the code for you.
Historically, it has been unlikely that anyone will program up a paper for someone else, unless the paper was unusually simple.
Historically, it has been much more common for people to have time to help debug problems in code that someone has already written.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by