Scala Image filter

Hi! My English is not good ; s Still learning. On studies i got a exercise to solve.
It must be simple program which:

Someone using a machine learning for user identification.
But usually users makes id proces in dark room.
Application have to go into the folder /in
read all of the files .png .jpg and after analize app have to save the files into folder /out.
During the analyze app have to tag every file “Dark” or “Light”, but every dark photo have to be dropped according to algorithm.
Image must be in range 0-100 where 0 is light 100 is dark.

exmaple

If image is white screen it have to be 0 if black 100.

When we run the script given an input folder “in”, output folder “out” and configured “cut off“ point of 55, then the final result should be this directory structure:
in/
perfectly_white.png
perfectly_black.jpg
colorful_image.jpg
out/
perfectly_white_bright_0.png
perfectly_black_dark_100.jpg
colorful_image_dark_55.jpg

It must be just a simple code in Scala, and it must work with all images which i put into folder /in.

Could someone help me :wink: ?

Yes, we can help.

What part of this are you stuck on? Can you show us what you have so far and explain why you’re having trouble taking it any further?

1 Like

I have so much troubles, becouse im still student, and i never before write in Scala/Java etc. Only C++ and that exercise i could do in C++, but i have to do in Scala.
I dont start it yet. I bought today book, and today i every hour spend on read a book or forum.

How i can write a simple app which makes:
-App takes images from dir /in and after that, calculate brightness range from 0(white) to 100(dark). -Returns images with tag name image for example, (dark_imageASDF.jpg/png) to dir /out

If the assignment as a whole seems daunting, you should break it down into parts. For example, your problem description begins with “App takes images from dir /in and after that…”. So you could begin by writing a program that just finds the image files in the input directory and prints the filenames to standard output. That’s a first step. Then move on to actually trying to open and read the image files. And so on. Break it down into steps, and then tackle the steps one at a time. If you get stuck on something specific, come here and ask a specific question.

1 Like

P.S. http://scalacookbook.com is a good source of code snippets that perform common tasks. Chapter 12 addresses the I/O aspects of your assignment.

1 Like

Im really newbie, my IDE is eclipse and i want start something like that.
i have SRC and in that i have IN folder with images, and OUT folder.
next is first Scalaobject names “ImageIO”

So how i can make that will read all of this image and next makes calculate that?
"
package main

import java.io.File
import java.nio.file.Files

object ImageIo {
type ImageName = String

def loadImages: Seq[(Image, ImageName)] = {
def inputFiles: Seq[(File, ImageName)] = {
val directory: File = new File(Config.inputDirectory)
val files: Seq[File] = directory.listFiles().filter(.isFile).toSeq
val names: Seq[ImageName] = files.map(
.getName)
files zip names
}
inputFiles.map(filesWithNames => (Image.fromFile(filesWithNames._1), filesWithNames._2))
}

def saveCopyWithMetadataToDisk(darknessLevel: DarknessLevel, imageName: ImageNme): String = {
def withMetaData: ImageName = {
val nameAndFormat: List[ImageName] = imageNme.split("\.").toList
val bright0rDark: String = if (darknessLevel < Config.cutOff) “bright” else “dark”
val withLevel: ImageName = s"${nameAndFormat.head}${brightOrDark}$darknessLevel"
s"$withLevel.${nameAndFormat.last}"
}
}"

IDK what im doing … still learning from book

What you have so far looks reasonable. What’s the next small way in which you want to improve this code? (You won’t get to a complete solution all in one go; you need to break it down into small, manageable steps that you can tackle one at a time.)