As the title says, I am trying to crop images using the axis extents which are already stored in individual variables. The variables refer to the 'baseFileName' for the image eg IMG_1234.jpg, so the corresponding variable is called 'x1234' (Matlab put the x there when I imported them in...). In each variable is X1, X2, Y1, Y2 eg [1600;3250;1600;2800].
My script will be run several times, so I want the script to be able to automatically look up the variable (and then the X Y data) needed each time the corresponding image file is loaded. The X Y will then be used to 'clip' the image to the area of interest.
This code is used to extract the image number from the original file name:
ImgName = regexpi(baseFileName, '(?<=IMG_)\d+', 'match', 'once');
A RGB image is loaded, which is then converted to grayscale for indexing purposes:
and at this point, I want to be able to look up the variable 'xImgName' eg 'x1234' and extract the axis extents to create a new image 'idx', I think, something similar to this:
idx = imcrop(I,[Y1 Y2 X1 X2] 1);
I am struggling with the bits in-between ie getting the code to look-up the right variable relative to the filename, and then getting the crop to be done to the size I need.
As I said before, the script will be run more than once on different image file names, so hard coding this is not going to work.
Could anyone offer any ideas as to how to tackle this? Thanks in advance.