Logical error regarding mouse input
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Ria3242
am 5 Okt. 2016
Kommentiert: Ria3242
am 2 Nov. 2016
Hello. I have an image of different sub images from which I crop different sub images at different times during processing. My image consists of 9 animals as 9 sub images. I want to crop them one by one by randomly getting mouse input and then crop the sub image which is clicked. I compare the values of x and y and then crop using imcrop function. the problem i'm facing is, when I want to crop sub image 7, the command line compares the input values and displays sub image 4. and so on with 5 instead of 8 and 6 instead of 9. Just these three sub images are not displayed or over-written.
My code is:
% x and y values for sub image 4
if(x>1 && x<175)
if(y>116 && y<235)
%code for displaying sub image 4
%and so on with 5 and 6
% x and y values for sub image 7
if(x>1 && x<175)
if(y>225 && y<340)
when I run these statements separately in the command line, the results are correct. but when working in my GUI, the results are as described above. During debugging, when I click on sub image 7, the exact values I get for x and y are x=135.2441 , y= 264.1670
I can't get why still the control gets in the if structure of sub image 4 having these values, as they take us for image 7, and then displays image 4 instead of 7. Please help me correct my calculations. Thanks !
2 Kommentare
Adam
am 5 Okt. 2016
Bearbeitet: Adam
am 5 Okt. 2016
I assume it is just a typo that your y ranges overlap between 225 and 235?
Your code will land in the first if statement though not the second. It depends what, if anything, else happens within the first if statement, but not the second. Either way, if there are no else statements then it should still fall into the nested if statements at the bottom even if it does something else first.
Logically there is obviously something going wrong in code that you have not shown us.
Akzeptierte Antwort
Guillaume
am 9 Okt. 2016
As Adam says, there must be something wrong some logic that you haven't shown us.
In any case, seeing so many if makes me cringe. Assuming the subimages touch each other, a much better way (and less error prone) of finding which image the user has clicked would be:
startx = [1, 175, 350]; %took a guess at the third column
starty = [1, 116, 235];
subimagenumber = sub2ind([3 3], find(y >= starty, 1), find(x >= startx, 1));
That's it, much simpler, no chance of error in one of the if.
If the subimages do not touch, or they're not all the same size, it gets a bit more complicated, but the same idea can be applied.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu 3-D Volumetric Image Processing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!