Skip to content

Conversation

@asabri97
Copy link
Collaborator

@asabri97 asabri97 commented Nov 11, 2025

🛠️ PR Summary

Made with ❤️ by Ultralytics Actions

🌟 Summary

Normalize UIImage orientation across SwiftUI and UIKit example apps to ensure consistent .up orientation for inference and UI rendering.

📊 Key Changes

  • Replaced CIContext-based orientation handling with UIGraphics normalization in both SwiftUI ContentView and UIKit ViewController helpers
  • Early return when image is already .up to avoid unnecessary work
  • Expanded unit tests for SwiftUI and UIKit to assert normalized images always have .up orientation across all orientations, including mirrored variants
  • Added validations for image dimensions and non-nil results after normalization

🎯 Purpose & Impact

  • Ensures consistent model inputs by removing orientation metadata ambiguity before processing
  • Reduces edge-case failures when users select photos with various EXIF orientations
  • Simplifies and stabilizes the orientation fix logic, improving maintainability and test coverage

@asabri97 asabri97 temporarily deployed to Release - TestFlight November 11, 2025 14:21 — with GitHub Actions Inactive
@asabri97 asabri97 linked an issue Nov 11, 2025 that may be closed by this pull request
@UltralyticsAssistant UltralyticsAssistant added bug Something isn't working fixed Bug has been resolved labels Nov 11, 2025
@UltralyticsAssistant
Copy link
Member

👋 Hello @asabri97, thank you for submitting a ultralytics/yolo-ios-app 🚀 PR! This is an automated review assistant; an engineer will follow up shortly. To ensure a seamless integration of your work, please review the following checklist:

  • Define a Purpose: Clearly explain the purpose of your fix or feature in your PR description, and link to any relevant issues. Ensure your commit messages are clear, concise, and adhere to the project's conventions.
  • Synchronize with Source: Confirm your PR is synchronized with the ultralytics/yolo-ios-app main branch. If it's behind, update it by clicking the 'Update branch' button or by running git pull and git merge main locally.
  • Ensure CI Checks Pass: Verify all Ultralytics Continuous Integration (CI) checks are passing. If any checks fail, please address the issues.
  • Update Documentation: Update the relevant documentation for any new or modified features.
  • Add Tests: If applicable, include or update tests to cover your changes, and confirm that all tests are passing.
  • Sign the CLA: Please ensure you have signed our Contributor License Agreement if this is your first Ultralytics PR by writing "I have read the CLA Document and I sign the CLA" in a new message.
  • Minimize Changes: Limit your changes to the minimum necessary for your bug fix or feature addition. "It is not daily increase but daily decrease, hack away the unessential. The closer to the source, the less wastage there is." — Bruce Lee

For more guidance, please refer to our Contributing Guide. Don’t hesitate to leave a comment if you have any questions. Thank you for contributing to Ultralytics! 🚀

@codecov
Copy link

codecov bot commented Nov 11, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copy link
Member

@UltralyticsAssistant UltralyticsAssistant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 PR Review

Made with ❤️ by Ultralytics Actions

The normalization helpers look solid; just add defer { UIGraphicsEndImageContext() } in both implementations so the graphics context is always released. Also, pruning the never-failing nil expectations in the new tests will keep the suite meaningful.

💬 Posted 4 inline comments

newImage = uiImage
}
return newImage
UIGraphicsBeginImageContextWithOptions(uiImage.size, false, uiImage.scale)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 MEDIUM: Nice simplification! One small request: could we wrap the drawing block with defer { UIGraphicsEndImageContext() }? That guarantees the context is torn down even if we add another exit path or the draw routine starts returning early, and it keeps us safe from leaks if this helper evolves.

newImage = uiImage
}
return newImage
UIGraphicsBeginImageContextWithOptions(uiImage.size, false, uiImage.scale)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 MEDIUM: Same feedback here—using defer { UIGraphicsEndImageContext() } around the render block would make sure the graphics context is always cleaned up, which protects us if the method later grows additional return points.


// Check if the function returns a valid image
#expect(correctedImageDown != nil, "Corrected image should not be nil")
#expect(correctedImageDown.imageOrientation == .up, "Normalized image should have .up orientation")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 LOW: getCorrectOrientationUIImage returns a non-optional UIImage, so this nil check will never fail. Dropping the assertion keeps the test focused on behaviors that can actually break.


// Check if the function returns a valid image
#expect(correctedImageDown != nil, "Corrected image should not be nil")
#expect(correctedImageDown.imageOrientation == .up, "Normalized image should have .up orientation")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 LOW: Same as the SwiftUI tests—since the helper returns a non-optional UIImage, this nil check cannot fail. Removing it will avoid a tautological assertion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working fixed Bug has been resolved

Projects

None yet

Development

Successfully merging this pull request may close these issues.

How to ensure correct image orientation?

4 participants