esimov / caire Goto Github PK
View Code? Open in Web Editor NEWContent aware image resize library
License: MIT License
Content aware image resize library
License: MIT License
14:21:32:/Users/balupton/Dropbox/Ben, Helen/Artwork Exports/Exports:master
> caire -in 3x -out 1024h -height=1024 -scale=true
Processing... /panic: runtime error: index out of range
goroutine 1 [running]:
github.com/esimov/caire.(*Carver).get(...)
/Users/esimov/Go/src/github.com/esimov/caire/carver.go:62
github.com/esimov/caire.(*Carver).ComputeSeams(0xc4200765a0, 0xc420053800, 0xc420052400, 0xc4231ee000, 0x400, 0x400)
/Users/esimov/Go/src/github.com/esimov/caire/carver.go:201 +0xfa2
github.com/esimov/caire.(*Processor).Resize.func1()
/Users/esimov/Go/src/github.com/esimov/caire/process.go:74 +0x116
github.com/esimov/caire.(*Processor).Resize(0xc420052400, 0xc420053800, 0x0, 0xc4200520c0, 0xffffffffffffffff, 0xc42138e000)
/Users/esimov/Go/src/github.com/esimov/caire/process.go:147 +0x8f6
github.com/esimov/caire.Resize(0x11db2a0, 0xc420052400, 0xc4200520c0, 0xc420052480, 0x113b93a, 0x3, 0x0)
/Users/esimov/Go/src/github.com/esimov/caire/process.go:41 +0x3b
github.com/esimov/caire.(*Processor).Process(0xc420052400, 0x11db4a0, 0xc42000c090, 0x11db4e0, 0xc42000c098, 0x0, 0x0)
/Users/esimov/Go/src/github.com/esimov/caire/process.go:177 +0x7e
main.main()
/Users/esimov/Go/src/github.com/esimov/caire/cmd/caire/main.go:143 +0x5c5
[2]:14:28:12:/Users/balupton/Dropbox/Ben, Helen/Artwork Exports/Exports:master
>
> caire --version
flag provided but not defined: -version
┌─┐┌─┐┬┬─┐┌─┐
│ ├─┤│├┬┘├┤
└─┘┴ ┴┴┴└─└─┘
Content aware image resize library.
Version: 1.1.0
-blur int
Blur radius (default 1)
-cc string
Cascade classifier
-debug
Use debugger
-face
Use face detection
-height int
New height
-in string
Source
-out string
Destination
-perc
Reduce image by percentage
-scale
Proportional scaling
-sobel int
Sobel filter threshold (default 10)
-square
Reduce image to square dimensions
-width int
New width
> uname -a
Darwin balbook-2018.local 18.0.0 Darwin Kernel Version 18.0.0: Wed Aug 22 20:13:40 PDT 2018; root:xnu-4903.201.2~1/RELEASE_X86_64 x86_64
Looks like building caire using openfaas is 31 step process. I am getting the following error at Step 15.
Errors received during build:
How do I go about this?
$ caire -in in.png -out out.jpg -perc=1 -width=150 -height=150 -debug=false
Processing... -
Error rescaling image: in.png. Reason: The generated image size should be less than original image size.
while specifying the enlargement size also have other problems as mentioned in #24
I'm new to Go. I have this version installed:
go version go1.9.3 darwin/amd64
I followed the basic installation instructions from the README:
$ go get github.com/esimov/caire/cmd/caire
$ go install
Afte running the go get
command, I end up with a go
folder in my filesystem's root. I'm not sure where I should execute go install
or what should happen next. Should I simply put the caire
executable in a specific folder to make it work?
Thanks for your help.
Roel
FYI, the image labeled "scotland" is in fact Gásadalur in the Faroe Islands, which is easily corroborated by a google image search. It's a beautiful place which I have been to many times, so I'd appreciate if the caption was fixed.
This project does look very interesting! I'd know that view from anywhere, though, so I thought I'd let you know.
my input image is of size 204x383 (portrait).
Whenever I run
caire -in in.jpg -out out.jpg -width=$((204*3/2)) -height=$((383*3/2))
or
caire -in in.jpg -out out.jpg -width=$((383*3/2)) -height=$((204*3/2))
The output image is in landscape (though it doesn't looks the same).
Input Size | Resize Size | Actual Output Size |
---|---|---|
204x383 | 306x574 | 306x192 |
204x383 | 574x306 | 574x306 |
hi link github.com/esimov/caire/cmd/caire is down?
I tried to rescale an image of the dimensions 2100 x 1300, scaling it down by 20 percent.
It took fifty minutes:
caire -in s.jpg -out out.jpg -perc=1 -width 20 -height 20
Processing... |
Rescaled in: 2952.92s
Saved as: out.jpg
Working on a recent macbook, go version go1.7.1 darwin/amd64
Am I doing something wrong?
I'm playing around with this as a library rather than a command-line utility, I wanted to do stuff in-memory without files and unfortunately Process
doesn't take an io.Writer
(PR incoming!) so for now, I simply copied this code:
src, _, err := image.Decode(file)
if err != nil {
return nil, err
}
img := imgToNRGBA(src)
res, err := Resize(p, img)
if err != nil {
return nil, err
}
Now this works fine going down in size but when going up in size, this happens:
panic: runtime error: index out of range
goroutine 1 [running]:
/Users/southclaws/go/src/github.com/esimov/caire/carver.go:108 +0xb4b
github.com/esimov/caire.(*Processor).Resize.func1()
/Users/southclaws/go/src/github.com/esimov/caire/process.go:65 +0x15d
github.com/esimov/caire.(*Processor).Resize(0xc420094090, 0xc420058840, 0x0, 0x0, 0x0, 0x0)
/Users/southclaws/go/src/github.com/esimov/caire/process.go:115 +0x8c4
github.com/esimov/caire.Resize(0x11cd280, 0xc420094090, 0xc42008a140, 0x0, 0x0, 0x0, 0x0)
/Users/southclaws/go/src/github.com/esimov/caire/process.go:35 +0x9c
main.resize(0x11cd480, 0xc420096070, 0x11cd4c0, 0xc420096078, 0x3fe999999999999a, 0x3fe0000000000000, 0x0, 0x0)
/Users/southclaws/Desktop/untitled folder/main.go:65 +0xabc
main.main()
/Users/southclaws/Desktop/untitled folder/main.go:27 +0x2ae
imageFile, err := os.Open(inPath)
if err != nil {
return err
}
defer imageFile.Close()
outFile, err := os.Create(outPath)
if err != nil {
return err
}
defer outFile.Close()
p := &caire.Processor{NewWidth: width, Scale: true}
return p.Process(imageFile, outFile)
I have a function along the lines of that, I've removed some superflous details.
panic: runtime error: index out of range
goroutine 217 [running]:
github.com/esimov/caire.(*Carver).get(...)
D:/Golibs/src/github.com/esimov/caire/carver.go:62
github.com/esimov/caire.(*Carver).ComputeSeams(0xc042f36240, 0xc0426cb140, 0xc0426e3300, 0xc0421aad80, 0x30, 0x30)
D:/Golibs/src/github.com/esimov/caire/carver.go:201 +0xf1b
github.com/esimov/caire.(*Processor).Resize.func1()
D:/Golibs/src/github.com/esimov/caire/process.go:74 +0x112
github.com/esimov/caire.(*Processor).Resize(0xc0426e3300, 0xc0426cb140, 0xc0426e3340, 0xc042121e00, 0xbb4c00, 0xc042cb4000)
D:/Golibs/src/github.com/esimov/caire/process.go:159 +0x892
github.com/esimov/caire.Resize(0xc58c20, 0xc0426e3300, 0xc0426e3340, 0xc042121e00, 0xb79560, 0x4, 0x0)
D:/Golibs/src/github.com/esimov/caire/process.go:41 +0x42
github.com/esimov/caire.(*Processor).Process(0xc0426e3300, 0xc59860, 0xc042fb6030, 0xc59880, 0xc042fb6038, 0x0, 0x4)
D:/Golibs/src/github.com/esimov/caire/process.go:177 +0x85
Because Go 1.16 offers support for embedded files, it's desirable to embed the cascade face classifier directly into the generated binary file. This way we can avoid having to provide the face classifier as a parameter for the CLI application.
resize an png image to a smaller image
the generated image should be a png file
the generated image is jpeg file
beenotung:caire$ caire -in 'ctrl police esc chasing.png' -out 'ctrl police esc chasing.1.png' -perc -width 20 -height 20
Processing... |
Rescaled in: 21.94s
Saved as: ctrl police esc chasing.1.png
beenotung:caire$ file ctrl\ police\ esc\ chasing*
ctrl police esc chasing.1.png: JPEG image data, baseline, precision 8, 690x262, frames 3
ctrl police esc chasing.png: PNG image data, 863 x 328, 8-bit/color RGB, non-interlaced
I used caire with a couple of images, and aside from the girl example in the README, I haven't gotten it to actually provide an output with any of the images I tried, even after 10-15mins. I have tried using different flags to make it faster, but it seems to be stuck processing forever.
Here's an example to reproduce my issue:
wget -O input.jpg "https://unsplash.com/photos/CaDoHQ3fB8w/download?force=true"
caire -in input.jpg -out output.jpg -face=false -scale -square -width=500 -height=500 -blur=0
Any suggestions?
Trying to take the library for a spin, but it seems like the Homebrew installation is out of date. After installing and running caire --help
I get the following output:
Usage of caire:
-blur int
Blur radius (default 1)
-debug
Use debugger
-height int
New height
-in string
Source
-out string
Destination
-perc
Reduce image by percentage
-sobel int
Sobel filter threshold (default 10)
-square
Reduce image to square dimensions
-width int
New width
Some notable flags missing are -scale
and -face
. I've tried to use both of these as my images never seem to finish processing.
I tried the alternative installation method, but when I run go get -u -f github.com/esimov/caire/cmd/caire
I get the following error (could open a separate issue for this if needed):
# gocv.io/x/gocv
imgproc.cpp:27:26: error: expected '(' for function-style cast or type construction
imgproc.cpp:30:19: error: expected '(' for function-style cast or type construction
imgproc.cpp:133:28: error: expected '(' for function-style cast or type construction
Anyone else experiencing something similar?
I would love a -square
option that will make the image be a square based on the shortest edge.
Hi, I'm Yevgeny Pats Founder of Fuzzit - Continuous fuzzing as a service platform.
We have a free plan for OSS and I would be happy to contribute a PR if that's interesting.
The PR will include the following
You can see our basic example fuzzitdev/example-go and you can see an example of "in the wild" integration google/syzkaller.
Let me know if this is something worth working on.
Cheers,
Yevgeny
I installed it from the AUR (`yay -S caire).
When I'm trying this command:
caire -perc=0 -width 3840 -height 1080 -in everyone.png -out test.png
than I'm getting this:
⚡ CAIRE is resizing the image... ✔
Error resizing the image:
Reason: scale option can not be used on image enlargement
How can I expand the image to 3840x1080?
I don't really know what to write here... (I'm not familiar with go)
That I'm getting the same image just bigger.
As I said in the beginning I installed it from the AUR and run it via CLI.
Hey!
I feel it'd be great having this as tool as a Web App for general public to make use of. Would you be interested in building a backend over this so that a Web App (which I could build) could use it as an API.
Anyone interested in such a project feel free start a discussion cause I see potential in this!
-ajayns
In order to make it easy to use caire as a library it would be to nice to have caire using golang modules.
For performance reasons we shouldn't encode each time the image raw pixel data into an image file when running the face detector. This way we can avoid to generate a new image at each iteration and also we can avoid of using a global TempImage
variable available across the whole codebase.
I have finished go install and it have no errors. But I use caire --help to test, it show -bash: caire: command not found. Please give me some instructions. Thank you.
how do you upload an image from a source
I'm using this library in a project of mine, and I realized that resizing was using an incredible amount of RAM, much more than I would have expected to process one image. I decided to run a memory profiler to confirm my suspicions. I tested this image, rescaling from from 2048x1536 to 1920x1080. These were the results [pdf] I got after running caire with pprof. Specifically, here was the code I used:
func resize(in io.Reader, out io.Writer) {
defer profile.Start(profile.MemProfile).Stop()
p := &caire.Processor {
NewWidth: 1920,
NewHeight: 1080,
Scale: true,
}
err := p.Process(in, out)
check(err)
}
As you can see, caire used 3.4 GB of RAM to process this one image. I decided to investigate further on what it was using this memory for, and focused on the reduce() function, which is the main function which is called repeatedly when resizing an image:
reduce := func() {
width, height := img.Bounds().Max.X, img.Bounds().Max.Y
c = NewCarver(width, height)
c.ComputeSeams(img, p)
seams := c.FindLowestEnergySeams()
img = c.RemoveSeam(img, seams, p.Debug)
imgs = append(imgs, img)
}
The program appends each iteration it creates to an imgs
slice, which from my understanding is only used when the input is a gif, since that slice will be used to reconstruct the frames of the gif. Since I was processing a jpg, I removed the line and ran the program through a profiler again, and here were the results [pdf]. Removing this one line reduces the memory usage from 3.4 GB to only 232 MB.
I tested the change on another image and found a similar reuction, from [1.8 GB] to [231 MB]. More testing could be done, but I would propose adding another parameter to the Processor struct, like 'IsGIF', then only appending the images to the slice if this is given as true, such as
if (p.IsGIF) {
imgs = append(imgs, img)
}
I was trying to resize an png
image of the dimension 1200 × 750
to 120 x 120
. However, the terminal output stuck at Processing... -
for minutes.
Hello,
I just gave caire a try against one of my images and it seems to be spinning non-stop.
./caire -in ./source.JPG -out ./dest.JPG -width 480 -height 720
And, I then changed to perc 20
and this worked but produced the image that is almost 3 times the original size.
Not sure what I am missing. Also, -debug
doesn't print anything ...
Let me know what additional info you need ...
Thanks!
what are the supported file extensions?? Are these supported -- file bmp, gif, jpg, jpeg, png, webp and svg?
Great work on this, I'm having fun just messing around with it.
Forgive me if this is obvious - but is there a way to hide the seams on the output file? Each result I have includes the red seams on the image.
Thanks!
When I try to rescale this image: https://wallhaven.cc/w/dgpj33 from its original size 3840x1080 to new size 3046x1050, this happens:
"cannot rescale to this size preserving the image aspect ratio" seems to always show up. I was under the impression that the whole purpose of this utility is to change the aspect ratio of the image?
Hi,
thank you for this awesome library. I aspire to use it in my application for "cropping" profile images to squares when they are not uploaded as squares.
But: The library does not seem to free its used memory when it's done processing which means my server hits memory limit after two or three users uploaded their image. (200MB to 1.5GB, depending on the image)
The code I used to resize images
Please remind me if I have missed something and there is an option to cleanup.
Hi, I get the same error every time I try to $ go get
:
$ export GOPATH="$HOME/go"
$ export PATH="$PATH:$GOPATH/bin"
$ go get -u -f github.com/esimov/caire/cmd/caire
# gocv.io/x/gocv
core.cpp: In function ‘cv::Mat* Mat_ConvertFp16(Mat)’:
core.cpp:80:5: error: ‘convertFp16’ is not a member of ‘cv’
cv::convertFp16(*m, *dst);
^
core.cpp: In function ‘void Mat_EigenNonSymmetric(Mat, Mat, Mat)’:
core.cpp:344:5: error: ‘eigenNonSymmetric’ is not a member of ‘cv’
cv::eigenNonSymmetric(*src, *eigenvalues, *eigenvectors);
^
core.cpp: In function ‘void Rotate(Mat, Mat, int)’:
core.cpp:380:5: error: ‘rotate’ is not a member of ‘cv’
cv::rotate(*src, *dst, rotateCode);
^
core.cpp:380:5: note: suggested alternatives:
In file included from /usr/include/c++/5/algorithm:62:0,
from /usr/include/opencv2/core/core.hpp:56,
from /usr/include/opencv2/opencv.hpp:47,
from core.h:24,
from core.cpp:1:
/usr/include/c++/5/bits/stl_algo.h:1431:5: note: ‘std::_V2::rotate’
rotate(_ForwardIterator __first, _ForwardIterator __middle,
^
/usr/include/c++/5/bits/stl_algo.h:1431:5: note: ‘std::_V2::rotate’
Could someone explain what am I doing wrong?
Because Github Actions offer more customization than Travis we can consider to migrate the CI part.
MacBook Pro 1014 mid
Hi, when I try to resize an image with size 2400 * 2400 with setting New_width = 180, scale = true, Square = true, face detection = true, it will not resize the image and output the original image after process, if Square option is removed, then it will resize the image correctly. I wonder if it is config problem or others?
Thank you
In your readme you said
i'm planning to implement my own face detection library to minimize the dependency tree
I wanted to create this ticket so I could watch it and get notified when this is done. I'd love to be able to just install th binary and not have to use homebrew or install any dependencies.
Thanks
When an image is resized both horizontally and vertically, the seam carving algorithm first will resize horizontally then vertically, but sometimes, depending on the image, this results with some unpleasant outcome. If we would process the image by applying the seam carving algorithm on horizontal and vertical axis intermittently normally the output would be much better.
Trying to run it on a MacbookPro (13" 2016 3.3ghz i7), but cant get anywhere past Processing message.
I've installed caire via homebrew, my sample image is the one used in the repo:
https://user-images.githubusercontent.com/883386/35498083-83d6015e-04d5-11e8-936a-883e17b76f9d.jpg
Command:
caire -in input.jpg -out output.jpg -width=300 -height=200
Processing... /
Any ideas?
I've tried the same on an Ubuntu docker container with go 1.10 and same result.
Any chance you could add this to Homebrew for easier packaging and updates on macOS?
Thinking about creating a logo for this repo. If anybody can came up with a nice idea can post it on this thread.
I do not see in the docs how to enlarge an image (for example -perc1 -width 20 reduce the width in 20%)
Hi
since caire provide the flag '-face', but when I specified this flag, caire will report a error that is 'please provide a face classifier file'. I know Pigo is face detector which can be used here, but I don't know how to use it. Could you please help me ? Thanks in advance.
Failed when scaling a jpg image of 204x383 to png of 408x766.
Tried to caire -in in.jpg -out out.jpg -square
, that was fine.
$ caire -in in.jpg -out out.png -width=408 -height=766
Processing... -panic: runtime error: index out of range
goroutine 1 [running]:
github.com/esimov/caire.(*Carver).get(...)
/home/beenotung/goroot/src/github.com/esimov/caire/carver.go:49
github.com/esimov/caire.(*Carver).ComputeSeams(0xc420b9c0c0, 0xc420058800, 0xc42001c1e0, 0xc420a6d600, 0x198, 0x198)
/home/beenotung/goroot/src/github.com/esimov/caire/carver.go:109 +0x6e9
github.com/esimov/caire.(*Processor).Resize.func1()
/home/beenotung/goroot/src/github.com/esimov/caire/process.go:66 +0x116
github.com/esimov/caire.(*Processor).Resize(0xc42001c1e0, 0xc420058800, 0xc4200e0080, 0xc420058340, 0xffffffffffffffff, 0xc4201d8000)
/home/beenotung/goroot/src/github.com/esimov/caire/process.go:122 +0x51f
github.com/esimov/caire.Resize(0x5ac2c0, 0xc42001c1e0, 0xc420058340, 0xc4200e0080, 0x51cdb0, 0x4, 0x0)
/home/beenotung/goroot/src/github.com/esimov/caire/process.go:35 +0x3b
github.com/esimov/caire.(*Processor).Process(0xc42001c1e0, 0x5ac4c0, 0xc42000c080, 0x5ac500, 0xc42000c088, 0x0, 0x0)
/home/beenotung/goroot/src/github.com/esimov/caire/process.go:138 +0x7e
main.main()
/home/beenotung/goroot/src/github.com/esimov/caire/cmd/caire/main.go:121 +0x54c
When generating an image at, for example, half "resolution", this tool creates undesirable effects as it tries to remove half the image data while keeping everything at it's current resolution, resulting in rather mangled output. The solution to this is to first resize the image using a traditional scaling method without applying any cropping, then passing the data to this tool to apply the cropping to the image.
It would be nice to see a flag, that when set, would automatically pre-scale an image before applying this algorithm to it.
eg:
Given an image of dimensions 2048x1536
if I supply a command similar to the following:
caire -in image.jpg -out thumb.jpg -width=1024 -height=500 -scale=1
it would be nice to see the tool first resize the image to 1024x768, then utilize it's existing algorithms to remove the final 268 pixels instead of its current implementation on trying to keep everything the same scale and having to remove much more data.
I don't know if keeping the original resolution image is beneficial for calculating better seems however.
It would be ideal if pipes were usable with the CLI for enabling more expanded use-cases. After having worked with ImageMagick in the past - I could see this being a highly requested feature.
With ImageMagick you can have the input arrive from a pipe, or have the output sent to a pipe.
Examples:
Pipe to file:
caire -in bridge.jpg -scale -perc 70 > small_bridge.jpg
Input from pipe:
caire -scale -perc 70 -out smaller_bridge.jpg < small_bridge.jpg
Input and output from pipe:
cat small_bridge.jpg | caire -scale -perc 70 > smaller_bridge.jpg
There are usages of pipes in the OpenFaaS CLI (also in Go) if that helps. https://github.com/openfaas/faas-cli
I get this error when I use the lib as described in this tutorial: https://getstream.io/blog/go-1-11-rocket-tutorial/
# github.com/esimov/caire ../go/pkg/mod/github.com/esimov/[email protected]/process.go:18:2: imported and not used: "fmt"
Is there something related to the way the tutorial imports CAIRE ? If I delete the "fmt" import myself, then it works fine.
Can this library be used in go code. If yes, there is no link for documentation.
after I run the resize successfully, it print out:
Rescaled in: 17.47s
Saved as: out.jpg
where 17.47s
and out.jpg
are in green color, other are same as console default color.
But the reset of the console (username:folder$ ) are still in green color.
It would be nice, if there was a method on Processor like Processor.Resize which took image.Image or something like Processor.Process which lets you control what you want to encode the image as.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.