development of an "image processing" application on back-end

Being a newbie to django, I am planing to build a mobile application. I generally know that django could be used for back-end development of mobile applications, but I want to have an image processing step done on the server and this is where I have problem and need help. where should I have my “image processing” application on the server? Can I use django for also creating my “image processing” steps?

This is what my application is going to do, in brief:

  • User takes a photo with mobile
  • The image is sent to the server
  • The back-end part (server-side) of the application verifies if the user has already registered with the application or not (user authentication)
  • in case of a registered user, an “image processing” algorithm would be run on the image and the “processed image” would be created.
  • Finally the “processed image” would be sent back to the user’s mobile.

Any help is appreciated.

Yes, this is perfectly possible with Django. You need to create at least two API endpoints:

  1. For authentication
  2. For accepting and image and returning a processed result.

I think django restframework would be handy here, especially for the authentication step: https://www.django-rest-framework.org/api-guide/authentication/.

1 Like

Dear timonweb,

Thanks for your reply, so I can use django for “user authentication” and “accepting image & returning the processed image”. I have a small problem here:

my “image processing” algorithm is a piece of code that I have developed it in Python right now. Architecturally, where am I supposed to put this computational code? should I put it beside other codes I develop in django? Is this concept true at all?

I’m not sure, but as far as I understood the back-end is made up of three main parts: a database, a framework (django) and some APIs (django). considering this architecture, where is the location of my “image processing” code?

It is better to imagine your application being made of three layers: a database, an API that does CRUD operations on the database, and a UI that sends information to the API and renders the response. The backend layer isn’t really a API and a framework; they’re essentially the same thing and you will use features from both as the API is what communicates with the UI layer. Any logic happens after the API is called and before it sends back its result.

You can create a view function in Django that receives the user’s photo, checks if the user is registered, then processes the image, saves it to the server, and sends it back to the user.

The UI layer would be both responsible for sending the appropriate data to Django and rendering the response it receives. You can process this data using Django REST and custom views you write.

Let me know if anything is still unclear.

2 Likes

You can import your processing library and use it in a view, here’s a pseudocode:

from fancyimageprocessinglibrary import image_processing_method 

@login_required
def process_image(request):
    # Get image objects from request
    source_image = request.FILES['file']
    
    # Pass image object to image processing and get a resulting image object
    processed_image = image_processing_method(source_image)
    
    # Return processed image as a streaming response 
    return StreamingHttpResponse(processed_image, content_type="image/jpeg")
1 Like

hey Valz, I m working on my first-ever full-stack app and trying to make something like this and using react native for my frontend, I was wondering would it be the same thing and then just send data from Django view to my react component?

Yes, Django can be used to create your image processing steps on the server. Django itself is a powerful web framework primarily used for backend development, but it can also handle image processing tasks with the help of libraries like Pillow.

Here’s a general outline of how you could implement your application using Django:

Receive the image: Set up a Django view to handle incoming image uploads from the mobile application.

User authentication: Implement user authentication using Django’s built-in authentication system or third-party packages like Django REST Framework’s token authentication. This step ensures that only registered users can access the image processing functionality.

Image processing: Write a function or a separate module to perform the image processing. You can use Python libraries like Pillow, OpenCV, or scikit-image for image processing tasks. Within your Django view, call this function or module to process the uploaded image.

Return the processed image: After processing the image, return the processed image to the mobile application. You may need to serialize the image data and send it back as a response to the client. You can also consult with software development experts.