Opening Five Random Images From a File - Python - image

I am coding a Convolutional Neural Network that identifies Brown Tail Moth nests in trees. For the first part of my program, I want to import the image file with all of the pictures of the trees and pick five random images from that folder (just to see if it actually has the right folder with the images). However, when I click "run", it shows an error:
Traceback (most recent call last):
File "C:\Users\eumel\AppData\Roaming\JetBrains\PyCharmCE2021.2\scratches\Final.py", line 20, in
image = random.choice(os.listdir(test_folder))
NotADirectoryError: [WinError 267] The directory name is invalid: 'C:\Users\eumel\Downloads\Photos-001 (4).zip'
I'm not sure if I have the code right for this, but I don't know how to fix it and have it show the images.
Can anyone help?

Related

Computer-aided remover of already-sorted images

My question is not removing duplicated/similar images. I need a tool to process a more complex process:
Find pictures I have manually removed in a folder
Apply this removal in another folder
Replace low-resolution pictures in a folder by High-resolution ones from another folder
I use Linux, but please propose solutions compatible with several OS if possible. I would also appreciate Free/Libre/OpenSource tools.
The below three examples explain the requirements
-1- Basic example: I have an old copy of my SD card on my computer (where I have already removed failed pictures) and I want these failed pictures (worst ones) be automatically removed from my Camera's SD card.
Folder "My-Computer" Folder "SD-Card" ACTION
I23001.JPG I23001.JPG keep duplicate
I23002.JPG I23002.JPG keep duplicate
I23003.JPG remove missing
I23004.JPG remove missing
I23005.JPG I23005.JPG keep duplicate
I23006.JPG remove missing
I23007.JPG remove missing
I23008.JPG I23008.JPG keep duplicate
I23009.JPG copy new picture
I23010.JPG copy new picture
I23011.JPG copy new picture
In real life, pictures are also copied on mobile phones, web gallery, cloud, backup... and failed pictures may also be removed on different devices...
-2- More complex example: I take picture using camera/smartphone/tablet. I also manually remove failed pictures (worst ones) on computer/camera/smartphone/tablet. We want best pictures being copied an all devices to view/show them.
"My-Computer" "SD-Card" "Smartphone" ACTION
I23001.JPG I23001.JPG I23001.JPG keep duplicate
I23002.JPG I23002.JPG ask user
I23003.JPG I23003.JPG ask user
I23004.JPG remove missing
I23005.JPG I23005.JPG I23005.JPG keep duplicate
P89001.JPG P89001.JPG keep duplicate
P89002.JPG P89002.JPG keep duplicate
P89003.JPG remove missing
P89004.JPG P89004.JPG keep duplicate
I23006.JPG I23006.JPG remove missing
I23007.JPG I23007.JPG remove missing
I23008.JPG I23008.JPG I23008.JPG keep duplicate
I23009.JPG copy new picture
I23010.JPG copy new picture
I23011.JPG copy new picture
P89005.JPG P89005.JPG keep duplicate
P89006.JPG copy new picture
P89007.JPG copy new picture
P89008.JPG copy new picture
-3- Very complex: I copy pictures from my camera to my smartphone using the camera's Wi-Fi access point, but the pictures are reduced (similar image content but not exact duplicate file). I also copy pictures to my friend's smartphone. We also take photos using our smartphone and copy some ones (best ones) to the other smartphone. And we also process the same with tablets. Manual removal is done on any device.
example too messed to be displayed here!
Analysis
List of duplicates finders:
Duplicate file finders on Wikipedia
Search word "duplicate" in image viewer comparison on Wikipedia
Interesting tools:
findimagedups from Jonathan H N Chin, perl script (and C lib) storing image fingerprints into a Berkley DB file and printing together filenames of images matching more than xx% similarity (pictures taken in burst mode may be flagged as similar)
findimagedupes version in Go
gThumb can also find/remove duplicates
Geeqie
imgSeek
digiKam and its Find Duplicate Images Tool
Visipics
dupeGuru Picture Edition
Tools lacking of similar image recognition:
fslint
duff
fdups
rmlint
Coding a new tool
As I did not (yet) find any solution I was thinking of developing a new software:
Modify a command line tools like findimagedups in order to provide the matching distance between images (similarity percentage)
This output may be a graph
each file is a node
edges (relations between files):
content matching (similarity percentage, crop, similar region)
in same folder, in a neighborhood folder
similar filename, successive filename numbering
similar date/time
similar metadata
similar resolution
For each group of content-similar nodes
one folder = one column
one file by raw, if duplicates in same folder (e.g. burst mode)
missing file in one folder = blank
similarity of files are provided in horizontal/vertical neighborhood only
Automatically selection of:
files to be replaced (low resolution replaced by high resolution, except in folder called "small")
files to be removed
User can display pictures and check connection properties

Any CLI tool to perform 3d texture mapping on the fly

I'm currently looking for a way to create a 'configurator' for a upholsters, similar to http://digitaldraping.com/configurator/furniture-sofa/?Cushions_Plain-Cream.png,Sofa_Stripe-Orange.png - you select your fabrics and they are 'drawn' on the sofa automatically.
Unfortunately, all the sites I've looked at seem to use pre-rendered transparent PNGs that are overlaid over each other to build up the full picture. The problem here is that we've figured out that we'd require over 120,000 different images to cover all models, fabrics etc!!
I've looked at a few 3d texture tools such as http://www.arahne.si/products/arah-drape.html, hoping that one of them would have a CLI option where you give it a pre-created wireframe, and a fabric to overlay, and it generates the required image on the fly, but so far everything seems to require real-time use of the GUI to use it.
So, is there a CLI tool that would do what I'm after, or can anyone suggest a way to manipulate the GUI automatically? (from a tech point of view, I'm comfortable with C, Bash, Python or PHP as a solution!)
Thanks!
ArahDrape 2.2 can now work from a command line without any GUI interface. You can also call ArahDrape as a C library. In this way, it can be used in a web server to create texture mapped images on the fly. The command line options are explained below.
ArahDrape 2.2j command line version, ©2015 Arahne
usage:
adCommand -o /tmp/outputImage.png -tN /home/user/texture.png [-hidemodel] [-divide 2] [-filterPNG] [-compressPNG 2] [-m /home/user/model.png] -owner name -activation 174b3cfb49e9 /home/user/project.drape
Input and output images can have png, .tif or .jpg extensions
-o output_image_file
-tN texture_image_file [N goes from 0 to 199]
-hidemodel will render all areas not in region as white
-divide N [N goes from 2 to 5] divide resulting image pixel size
-filterPNG if you do not filter it, rendering is faster
-compressPNG N [N goes from 0 to 9] lower number saves faster, but bigger files
-m model_image_file use this if you want to replace model image from the project; must have same pixel size
-owner owner_name pass the given owner name
-activation activation_code pass the given activation code
last parameter should be ArahDrape project file
All files should be entered with full path.
If you need spaces in filenames, use quotes "" around the filename.
If you provide only Owner name, without activation code, program returns registration code.
ArahDrape supports batch export.
Open ArahDrape project, click on texture you wish to replace, put all your texture in a directory, select from menu
Textures > Browse textures, and as you click the texture to load it, program will save the draped picture. If you have thousands of images, use keyboard shortcut = and program will automatically do them all.
Alpha channel transparency is supported in loading model images or textures, and saving the draped images, as long as you use PNG or TIFF.
Please check this video to see how
ArahDrape works in batch mode.
we (http://digitaldraping.com/) can do just what you are asking. We have two options creating images and rendering a meshed image on the fly. Just get in touch if you still need this solution.

Problems when using RyTrack, the GUI-based particle tracking interface written in IDL

I am using RyTrack(http://sun.iwu.edu/~gspaldin/rytrack.html) to do particle trakcing, and when I follow the instruction, as below
INPUTS: (Once the GUI has been called ...)
1) Image directory: The path to the image sequence files of interest.
Windows example: C:/myfolder/*.tif
UNIX example: ~/myfolder/*.tif
(Note: The program can accept tif, jpg, or bmp formats, among others.)
start: begins a frame-by-frame display. The original image is shown in the
top displayand the filtered image in the bottom display.
Once started, the image processing
can be changed on the fly, and the results of these changes will become
evident in the bottom image."
after i clicked start, nothing happens and IDL said
IDL> rytrack
Widgets are initialized
XMANAGER: Caught unexpected error from client application. Message follows...
Attempt to call undefined procedure/function: 'RYTRACK_EVENT'.
Execution halted at: XMANAGER_EVLOOP_STANDARD 478 H:\RSI\IDL55\lib\xmanager.pro
XMANAGER 708 H:\RSI\IDL55\lib\xmanager.pro
RYTRACK 856 E:\Dropbox\Research\Resources\rytrack.pro
May I ask how could I fix this and let it work?
Thanks.
It worked for me. Were you running it from the .sav file or the .pro file?

How to draw a rectangle on a wx.StaticBitmap image in wxpython

How can I draw a rectangle on an my wx.StaticBitmap image called "bitmap_1" using a dc.Rectangle? I have co-ordinates((754, 483)) on where the rectangle must be drawn.
dc.DrawRectangle(10, 10, 200, 200)` this gives an error
Traceback (most recent call last):
File "C:\Users\Foster\Documents\Roland\ims project\newtagging2.py", line 129, in OnImageMouseOver
NameError: global name 'dc' is not defined
The error is because you haven't defined what dc is.
You want to take a look at wxMemoryDC.
MemoryDC creates a DC that can be used to draw to bitmaps in memory (as opposed to the display)
You'll want to draw on bitmap_1 before passing it to StaticBitmap like this:
dc= wx.MemoryDC(bitmap_1)
dc.DrawRectangle(10,10,200,200)
dc.SelectObject(wx.NullBitmap) #This de-selects the bitmap
This article should help you using DCs as well.

Create RGBA Colormap in PyGTK

I have a project in Python 2.7 and PyGTK.
I need to create a transparent background window, but still be able to display images (pixmap and mask based) and other objects inside of the window.
I am using the following code, but no image objects are showing up in Ubuntu (Oneric Ocelot), and I'm getting an error, posted below, (though the window otherwise displays, with its button objects). This won't even render in Windows 7 (this error also posted below).
def expose(widget, event):
cr = widget.window.cairo_create()
# Sets the operator to clear which deletes everything below where an object is drawn
cr.set_operator(cairo.OPERATOR_CLEAR)
# Makes the mask fill the entire window
cr.rectangle(0.0, 0.0, *widget.get_size())
# Deletes everything in the window (since the compositing operator is clear and mask fills the entire window
cr.fill()
# Set the compositing operator back to the default
cr.set_operator(cairo.OPERATOR_OVER)
hab_fish_win = gtk.Window()
hab_fish_win.resize(640, 480)
hab_fish_win.set_resizable(False)
hab_fish_win.set_decorated(False)
hab_fish_win.set_has_frame(False)
hab_fish_win.set_position(gtk.WIN_POS_CENTER)
hab_fish_win.set_app_paintable(True)
screen = hab_fish_win.get_screen()
rgba = screen.get_rgba_colormap()
hab_fish_win.set_colormap(rgba)
hab_fish_win.connect('expose-event', expose)
hab_fish_win.show()
WINDOWS 7 RUN:
Traceback (most recent call last): File "C:\Users\user\MousePaw
Games\Word4Word\PYM\fishtest2.py", line 337, in
HAB_FISH() File "C:\Users\user\MousePaw Games\Word4Word\PYM\fishtest2.py", line 100, in init
hab_fish_win.set_colormap(rgba) TypeError: Gtk.Widget.set_colormap() argument 1 must be gtk.gdk.Colormap, not
None
A quick "print rgba" confirms that rgba is "None", thus the error.
UBUNTU "ONERIC OCELOT" RUN:
Gtk Warning: Attempt to draw a drawable with depth 24 to a drawable with depth 32
What is going on? I desperately need that transparent background for the window.
Okay, after hours of research, I have found that Windows does not support this sort of transparency. As for the Linux error, I don't know.
I'm porting to PyGObject, and using another method for my ends. I would suggest readers of this answer look into it.

Resources