Problem using the imcrop function for batch image cropping!
Show older comments
Hi all,
I wrote a little batch image cropping function based on one my friend wrote but I found it kept getting the same error (after I sorted out the other problems). It seems there is some problem with the imcrop function but I don't know what as I think it is being used in the right way. The aim of the function is to crop all .tif files in a specific folder by the same amount (they all have quite different file names). The images are all the same size to start with. Anyone have any thoughts? Any help would be most appreciated.
The function is:
function fun_im_crop_enlarged_test(basePath)
tifFiles = dir([basePath, '*.tif']);
cropPos = [20, 20, 40, 40];
for k = 1:length(tifFiles)
path1 = [basePath, tifFiles(k).name];
data=imread(path1);
cropIm = imcrop(data, cropPos);
path2 = char([basePath,'_crop_', tifFiles(k).name]);
imwrite(cropIm, path2);
end
The error I am getting is:
??? Error using ==> imcrop>checkCData at 381
Invalid input image.
Error in ==> imcrop>parseInputs at 252
checkCData(a);
Error in ==> imcrop at 94
[x,y,a,cm,spatial_rect,h_image,placement_cancelled] = parseInputs(varargin{:});
Error in ==> fun_im_crop_enlarged_test at 24
cropIm = imcrop(data, cropPos);
Accepted Answer
More Answers (1)
i'd like to share with you some of image cropping codes i am testing.it helps me crop tiff image or other image formats with a few clicks. please have a test and see whether it helps you or not. let me know if it is working. private void button1_Click(object sender, EventArgs e) { string fileName = "c:/Sample.png";
REImage reImage = REFile.OpenImageFile(fileName);
ImageProcessing.ApplyCrop(reImage, 80, 80, 500, 500);
REFile.SaveImageFile(reImage, "c:/reimage.png", new PNGEncoder());
}
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!