Cropping image into multiple images at certain coordinates, but the positions need verification first

I have an image of a test chart that I scanned with a scanner. The thing I want to do is cut the image in to pieces (rectangles) at a coordinate with a given size. I've tried this:
imcrop();
this let's you make a rectangle that will crop out. (but it wont be the right size from the start)
imcrop([xpos, ypos, w, h);
this lets you define a size and a coordinate but it wont let you verify if it's the right place on the image.
Is there a way of combining both? I want to get the x,y,w,h out of a matrix and then it should show on a plot, if it covers the area I want it to cover I can go on to the next step. and when they are all in the right place (they should be initially but if they aren't I still want to change the position) I want to press a button and have it cut the pieces out. The cutting shouldn't be so hard but I can't think of a way to show all rectangles at the same time, and then press a button to do all cuts at the same time.
I hope you understand my problem, english isn't my main language so I understand it might be a little vague.
Kind regards,
Thomas

Answers (2)

The main problem for now is that Matlab should show the crop-rectangles before actually cropping them, to verify if the rectangles are at the right place. I was thinking that I should maybe show the rectangles at positions with imrec, then save the position and then use these positions to crop with imcrop.
Any ideas on this?
Kind regards,
Thomas

1 Comment

Sorry for not commenting on my own question, I should've done that. I'm not very familiar with this user forum yet.

Sign in to comment.

I'm not sure what you're talking about. Calling imcrop() with no arguments does let you click and drag out a box and give you handles for adjusting the sides. Then you can double click inside the box.

4 Comments

I know, it does let you click and drag, but I want the box to be at specific coordinates (so I don't have to rescale and drag every box into position). For example: the box surrounds a grayscale patch on a test chart scan, the coordinates of the patch are known from en excel file, if the testchart isn't scanned in right (as in there is a few pixel outside the scan or something) the box should be dragged to the right position. And then the crop is made. I hope this clears up my question.
Sorry, it appears that you can't "preload" the box with predefined coordinates. If the user confirms the box, then the user must click and drag it out initially. You can't get them started with some box in a predefined location and size. It's a good idea though - you can send that in as a request for enhancement.
Allright, I'll do that for sure! Found another way to do it (kind off)
h = imrect(gca, [10 10 100 100]);
wait(h);
pos=getPosition(h);
imcrop(chart,pos);
Is there a way to show multiple imrect at the same time? instead of having to click each one individually?
I don't know - never tried. What if you do this:
h1 = imrect(gca, [10 10 100 100]);
h2 = imrect(gca, [120 120 100 100]);
h3 = imrect(gca, [230 230 100 100]);
wait(h1);
wait(h2);
wait(h3);
Not sure, though, if they're have to click on them in the same order they were put up. Would just have to try it and see.

Sign in to comment.

Products

Asked:

on 23 Mar 2015

Commented:

on 24 Mar 2015

Community Treasure Hunt

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

Start Hunting!