Cody

Problem 44958. Crop an Image

Solution 1953551

Submitted on 30 Sep 2019 by Nikolaos Nikolaou
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test Status Code Input and Output
1   Pass
I = [[magic(8), ones(8,4), magic(8)];[zeros(10,5),magic(10), zeros(10,5)]; [magic(5),zeros(5,10),magic(5)]]; assert(isequal(crop_image(I,9,6,10,10),magic(10)));

I = 64 2 3 61 60 6 7 57 1 1 1 1 64 2 3 61 60 6 7 57 9 55 54 12 13 51 50 16 1 1 1 1 9 55 54 12 13 51 50 16 17 47 46 20 21 43 42 24 1 1 1 1 17 47 46 20 21 43 42 24 40 26 27 37 36 30 31 33 1 1 1 1 40 26 27 37 36 30 31 33 32 34 35 29 28 38 39 25 1 1 1 1 32 34 35 29 28 38 39 25 41 23 22 44 45 19 18 48 1 1 1 1 41 23 22 44 45 19 18 48 49 15 14 52 53 11 10 56 1 1 1 1 49 15 14 52 53 11 10 56 8 58 59 5 4 62 63 1 1 1 1 1 8 58 59 5 4 62 63 1 0 0 0 0 0 92 99 1 8 15 67 74 51 58 40 0 0 0 0 0 0 0 0 0 0 98 80 7 14 16 73 55 57 64 41 0 0 0 0 0 0 0 0 0 0 4 81 88 20 22 54 56 63 70 47 0 0 0 0 0 0 0 0 0 0 85 87 19 21 3 60 62 69 71 28 0 0 0 0 0 0 0 0 0 0 86 93 25 2 9 61 68 75 52 34 0 0 0 0 0 0 0 0 0 0 17 24 76 83 90 42 49 26 33 65 0 0 0 0 0 0 0 0 0 0 23 5 82 89 91 48 30 32 39 66 0 0 0 0 0 0 0 0 0 0 79 6 13 95 97 29 31 38 45 72 0 0 0 0 0 0 0 0 0 0 10 12 94 96 78 35 37 44 46 53 0 0 0 0 0 0 0 0 0 0 11 18 100 77 84 36 43 50 27 59 0 0 0 0 0 17 24 1 8 15 0 0 0 0 0 0 0 0 0 0 17 24 1 8 15 23 5 7 14 16 0 0 0 0 0 0 0 0 0 0 23 5 7 14 16 4 6 13 20 22 0 0 0 0 0 0 0 0 0 0 4 6 13 20 22 10 12 19 21 3 0 0 0 0 0 0 0 0 0 0 10 12 19 21 3 11 18 25 2 9 0 0 0 0 0 0 0 0 0 0 11 18 25 2 9 Icrop = 92 99 1 8 15 67 74 51 58 40 0 0 0 0 0 98 80 7 14 16 73 55 57 64 41 0 0 0 0 0 4 81 88 20 22 54 56 63 70 47 0 0 0 0 0 85 87 19 21 3 60 62 69 71 28 0 0 0 0 0 86 93 25 2 9 61 68 75 52 34 0 0 0 0 0 17 24 76 83 90 42 49 26 33 65 0 0 0 0 0 23 5 82 89 91 48 30 32 39 66 0 0 0 0 0 79 6 13 95 97 29 31 38 45 72 0 0 0 0 0 10 12 94 96 78 35 37 44 46 53 0 0 0 0 0 11 18 100 77 84 36 43 50 27 59 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 17 24 1 8 15 0 0 0 0 0 0 0 0 0 0 23 5 7 14 16 0 0 0 0 0 0 0 0 0 0 4 6 13 20 22 0 0 0 0 0 0 0 0 0 0 10 12 19 21 3 0 0 0 0 0 0 0 0 0 0 11 18 25 2 9 Icrop = 92 99 1 8 15 67 74 51 58 40 98 80 7 14 16 73 55 57 64 41 4 81 88 20 22 54 56 63 70 47 85 87 19 21 3 60 62 69 71 28 86 93 25 2 9 61 68 75 52 34 17 24 76 83 90 42 49 26 33 65 23 5 82 89 91 48 30 32 39 66 79 6 13 95 97 29 31 38 45 72 10 12 94 96 78 35 37 44 46 53 11 18 100 77 84 36 43 50 27 59

2   Pass
I = [[magic(8), ones(8,4), magic(8)];[zeros(10,5),magic(10), zeros(10,5)]; [magic(5),zeros(5,10),magic(5)]]; assert(isequal(crop_image(I,19,1,5,10),[magic(5),zeros(5)]));

I = 64 2 3 61 60 6 7 57 1 1 1 1 64 2 3 61 60 6 7 57 9 55 54 12 13 51 50 16 1 1 1 1 9 55 54 12 13 51 50 16 17 47 46 20 21 43 42 24 1 1 1 1 17 47 46 20 21 43 42 24 40 26 27 37 36 30 31 33 1 1 1 1 40 26 27 37 36 30 31 33 32 34 35 29 28 38 39 25 1 1 1 1 32 34 35 29 28 38 39 25 41 23 22 44 45 19 18 48 1 1 1 1 41 23 22 44 45 19 18 48 49 15 14 52 53 11 10 56 1 1 1 1 49 15 14 52 53 11 10 56 8 58 59 5 4 62 63 1 1 1 1 1 8 58 59 5 4 62 63 1 0 0 0 0 0 92 99 1 8 15 67 74 51 58 40 0 0 0 0 0 0 0 0 0 0 98 80 7 14 16 73 55 57 64 41 0 0 0 0 0 0 0 0 0 0 4 81 88 20 22 54 56 63 70 47 0 0 0 0 0 0 0 0 0 0 85 87 19 21 3 60 62 69 71 28 0 0 0 0 0 0 0 0 0 0 86 93 25 2 9 61 68 75 52 34 0 0 0 0 0 0 0 0 0 0 17 24 76 83 90 42 49 26 33 65 0 0 0 0 0 0 0 0 0 0 23 5 82 89 91 48 30 32 39 66 0 0 0 0 0 0 0 0 0 0 79 6 13 95 97 29 31 38 45 72 0 0 0 0 0 0 0 0 0 0 10 12 94 96 78 35 37 44 46 53 0 0 0 0 0 0 0 0 0 0 11 18 100 77 84 36 43 50 27 59 0 0 0 0 0 17 24 1 8 15 0 0 0 0 0 0 0 0 0 0 17 24 1 8 15 23 5 7 14 16 0 0 0 0 0 0 0 0 0 0 23 5 7 14 16 4 6 13 20 22 0 0 0 0 0 0 0 0 0 0 4 6 13 20 22 10 12 19 21 3 0 0 0 0 0 0 0 0 0 0 10 12 19 21 3 11 18 25 2 9 0 0 0 0 0 0 0 0 0 0 11 18 25 2 9 Icrop = 17 24 1 8 15 0 0 0 0 0 0 0 0 0 0 17 24 1 8 15 23 5 7 14 16 0 0 0 0 0 0 0 0 0 0 23 5 7 14 16 4 6 13 20 22 0 0 0 0 0 0 0 0 0 0 4 6 13 20 22 10 12 19 21 3 0 0 0 0 0 0 0 0 0 0 10 12 19 21 3 11 18 25 2 9 0 0 0 0 0 0 0 0 0 0 11 18 25 2 9 Icrop = 17 24 1 8 15 0 0 0 0 0 23 5 7 14 16 0 0 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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Icrop = 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Icrop = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

4   Pass
I = [1 2 3 4;5 6 7 8]; assert(isequal(crop_image(I,2,2,1,3),[6 7 8]));

I = 1 2 3 4 5 6 7 8 Icrop = 6 7 8 Icrop = 6 7 8

Suggested Problems

More from this Author13

Community Treasure Hunt

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

Start Hunting!