Skip to content

Updating the code #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 45 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
36dce6d
This branch contains a update for python3.x and a better function to …
Sep 19, 2022
789170e
This branch contains an update for python3.x and a better function to…
Sep 19, 2022
3cd561c
This commit contains changes in fseg_filters.py, which now contains o…
Sep 19, 2022
286771e
Need to updathe readme.md, docs and overlay function save the paramet…
Sep 20, 2022
32cb54f
Need to updathe readme.md and docs. For now, it's saving the final im…
Sep 20, 2022
a0208e9
This commit contains an update on readme.md and a requirements.txt to…
Sep 20, 2022
e1cbcf1
This commit contains an upgrade to requirements.txt and to some funct…
Sep 20, 2022
f6d8add
This commit contains a pyhthon notebook with an example on how you ca…
Sep 20, 2022
192b9ab
Just a safe commit before creating CI/CD for conda
Sep 22, 2022
3a210a9
Testing ci/cd for this repo
borin98 Sep 22, 2022
ad35a34
Chaning the Python 3.10 to 3.9
Sep 22, 2022
9260144
Chaning the Python 3.10 to 3.9
Sep 22, 2022
1b5ee8f
Chaning the Python 3.10 to 3.9
Sep 22, 2022
b6543a9
Removing the test version
Sep 22, 2022
ba30f76
Trying to add an image test to run into a function
Sep 22, 2022
e61338e
Trying to add an image test to run into a function
Sep 22, 2022
58e929e
Trying to add an image test to run into a function
Sep 22, 2022
d84c43b
Trying to add an image test to run into a function
Sep 22, 2022
7667547
Trying to add an image test to run into a function
Sep 22, 2022
e3b9964
Trying to add an image test to run into a function
Sep 22, 2022
24a4d7d
Trying to add an image test to run into a function
Sep 22, 2022
a297b24
Trying to add an image test to run into a function
Sep 22, 2022
a5f6fa2
Trying to add an image test to run into a function
Sep 22, 2022
0ed7466
Trying to add an image test to run into a function
Sep 22, 2022
0bd4dbf
Trying to add an image test to run into a function
Sep 22, 2022
8bdbdd3
Trying to add an image test to run into a function
Sep 22, 2022
3e7b1b1
Updating with an image to test the dev branch
Sep 22, 2022
20a7ad8
This commit contains docts and types for variables in fseg_filters.py
Sep 22, 2022
9a9f58e
Merge branch 'main' into updatePython
Sep 22, 2022
89a563f
This commit contains a documentation upgrade and types for the script…
Sep 26, 2022
4814449
This commit just updates a TODO to create a loading bar
Sep 27, 2022
04ff45b
Renaming the jupyTest.ipynb as ExampleJupyter.ipynb
Sep 27, 2022
50412b4
Create a prototype to separate the masks
Sep 29, 2022
1f8d903
This commit contains a new function to print messagens, more info in …
Sep 30, 2022
06860f1
This commit contains a TODO for documentation in args section, some c…
Oct 4, 2022
2359a7a
This commit contains an update to receive more parameters in args and…
Oct 4, 2022
37c4867
Changing CI/CD
Oct 4, 2022
81613d7
Changing CI/CD
Oct 4, 2022
b22e33b
Changing CI/CD to run in FctSeg.py
Oct 4, 2022
8019673
Merge branch 'updatePython'
Oct 4, 2022
62d48ed
updating the default values
Oct 10, 2022
3bd3a22
Creating a new parameter in FctSeg.py that allows to pass a filter ba…
Oct 10, 2022
62db003
Creating a new parameter in FctSeg.py that allows to pass a filter ba…
Oct 10, 2022
a05e888
Merge branch 'updatePython'
Oct 10, 2022
21cd757
Merge branch 'master' into main
borin98 Sep 12, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .github/Images/house.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 41 additions & 0 deletions .github/workflows/python-package-conda.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Python Package using Conda

on: [ push ]

jobs:
build-linux:
runs-on: ubuntu-latest
strategy:
max-parallel: 5

steps:
- uses: actions/checkout@v3
- name: Set up Python 3.10.4
uses: actions/setup-python@v3
with:
python-version: 3.10.4
- name: Add conda to system path
run: |
# $CONDA is an environment variable pointing to the root of the miniconda directory
echo $CONDA/bin >> $GITHUB_PATH
# - name: Install dependencies
# run: |
# conda env update --file environment.yml --name base
# - name: Lint with flake8
# run: |
# conda install flake8
# # stop the build if there are Python syntax errors or undefined names
# flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
# flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
# - name: Test with pytest
# run: |
# conda install pytest
# pytest
- name: Installing requirements
run: |
pip install -r requirements.txt

- name: Running an example Image
run: |
python3 FctSeg.py -f ".github/Images/house.png" -shape_size 0 0 -ws 25 -dtype "uint8" -ws 25 -segn 0 -omega 0.045 -nonneg_constraint True -save_dir "" -save_file_name ""
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/Images/
/.idea/
/ResultImages/
123 changes: 123 additions & 0 deletions ExampleJupyter.ipynb

Large diffs are not rendered by default.

279 changes: 218 additions & 61 deletions FctSeg.py

Large diffs are not rendered by default.

49 changes: 31 additions & 18 deletions FctSeg_seed.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
"""
import time
import numpy as np
from fseg_filters import image_filtering
import matplotlib.pyplot as plt
import argparse
import cv2

from scipy import linalg as LAsci
from skimage import io
from utils.fseg_filters import image_filtering, overlay


def SHcomp(Ig, ws, BinN=11):
Expand All @@ -21,6 +21,7 @@ def SHcomp(Ig, ws, BinN=11):
:return: local spectral histogram at each pixel
"""
h, w, bn = Ig.shape
ws = int(ws)

# quantize values at each pixel into bin ID
for i in range(bn):
Expand All @@ -31,14 +32,14 @@ def SHcomp(Ig, ws, BinN=11):
b_interval = (b_max - b_min) * 1. / BinN
Ig[:, :, i] = np.floor((Ig[:, :, i] - b_min) / b_interval)

Ig[Ig >= BinN] = BinN-1
Ig[Ig >= BinN] = BinN - 1
Ig = np.int32(Ig)

# convert to one hot encoding
one_hot_pix = []
for i in range(bn):
one_hot_pix_b = np.zeros((h*w, BinN), dtype=np.int32)
one_hot_pix_b[np.arange(h*w), Ig[:, :, i].flatten()] = 1
one_hot_pix_b = np.zeros((h * w, BinN), dtype=np.int32)
one_hot_pix_b[np.arange(h * w), Ig[:, :, i].flatten()] = 1
one_hot_pix.append(one_hot_pix_b.reshape((h, w, BinN)))

# compute integral histogram
Expand All @@ -60,7 +61,7 @@ def SHcomp(Ig, ws, BinN=11):

integral_hist_1 = integral_hist_pad[ws + 1 + ws:, ws + 1 + ws:, :]
integral_hist_2 = integral_hist_pad[:-ws - ws - 1, :-ws - ws - 1, :]
integral_hist_3 = integral_hist_pad[ws + 1 + ws:, :-ws - ws -1, :]
integral_hist_3 = integral_hist_pad[ws + 1 + ws:, :-ws - ws - 1, :]
integral_hist_4 = integral_hist_pad[:-ws - ws - 1, ws + 1 + ws:, :]

sh_mtx = integral_hist_1 + integral_hist_2 - integral_hist_3 - integral_hist_4
Expand All @@ -75,7 +76,7 @@ def SHcomp(Ig, ws, BinN=11):
def Fseg(Ig, ws, seeds):
"""
Factorization based segmentation
:param Ig: a n-band image
:param Ig: an n-band image
:param ws: window size for local special histogram
:param seeds: list of coordinates [row, column] for seeds. each seed represent one type of texture
:param omega: error threshod for estimating segment number. need to adjust for different filter bank.
Expand Down Expand Up @@ -105,9 +106,26 @@ def Fseg(Ig, ws, seeds):


if __name__ == '__main__':
parser = argparse.ArgumentParser()

parser.add_argument("-f", "--file", help="file path")
parser.add_argument("-ws", "--window_size", help="window size for local special histogram")
parser.add_argument("-s", "--seeds",
help="list of coordinates [row, column] for seeds. each seed represent one type of texture")
parser.add_argument("-save_dir", "--save_dir", help="path with the folder to save the file")
parser.add_argument("-save_file_name", "--save_file_name",
help="file name with the extension to save the final result")
args = parser.parse_args()

file_path = args.file
ws = int(args.window_size)
#seeds = args.seeds
save_dir = args.save_dir
save_file_name = args.save_file_name

time0 = time.time()
# an example of using Fseg
img = io.imread('M1.pgm')
img = cv2.imread(file_path, 0)

# define filter bank and apply to image. for color images, convert rgb to grey scale and then apply filter bank
filter_list = [('log', .5, [3, 3]), ('log', 1.2, [7, 7])]
Expand All @@ -120,15 +138,10 @@ def Fseg(Ig, ws, seeds):
seeds = [[60, 238], [160, 160], [238, 60]] # provide seeds

# run segmentation. try different window size
seg_out = Fseg(Ig, ws=19, seeds=seeds)
seg_out = Fseg(Ig, ws=ws, seeds=seeds)

print 'FSEG runs in %0.2f seconds. ' % (time.time() - time0)
print('FSEG runs in %0.2f seconds. ' % (time.time() - time0))
title = "Plot using ws={}".format(ws)

# show results
fig, ax = plt.subplots(ncols=2, sharex=True, sharey=True, figsize=(10, 5))
ax[0].imshow(img, cmap='gray')
seeds = np.array(seeds)
plt.plot(seeds[:, 1], seeds[:, 0], 'r*')
ax[1].imshow(seg_out, cmap='gray')
plt.tight_layout()
plt.show()
overlay(img, seg_out, 0.6, cmap="viridis", save_fig=save_dir + save_file_name, save_dir=save_dir, plot_title=title)
2 changes: 0 additions & 2 deletions M1.pgm

This file was deleted.

359 changes: 0 additions & 359 deletions M2.pgm

This file was deleted.

Loading