5

I´m trying to use measure profile to detect fluorescence in a serie of tubes so I write the following code

import numpy as np
import matplotlib.pyplot as plt
from scipy import ndimage
from skimage.measure import profile_line
import os
import argparse
import string  
from PIL import Image


plt.rcParams['font.size']=16
plt.rcParams['font.family'] = 'sans-serif'


ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required=True, help="Path to the image")
args = vars(ap.parse_args())
imagen = Image.open(args["image"]) 
imagename=args["image"]  

img = np.array(imagen)

#profile position
start=(0,35)
end=(1300,35)

#profile_line
profile = profile_line(img,start,end, linewidth=5)
fig, ax = plt.subplots(2,1,figsize=(15,9))
ax[0].imshow(imagen, cmap=plt.cm.gist_earth, interpolation='gaussian',origin='lower',alpha=1)
ax[0].plot([start[0],end[0]],[start[1],end[1]],'r-',lw=3)
ax[1].plot(profile)
ax[1].set_title('data points = '+str(profile.shape[0])+'')
plt.tight_layout()
plt.savefig("scipy.jpg")

But I got

result

Original image is original ANy suggestions ? it falls at 100 in the x-axis...

omaqIX
  • 145
  • 11

1 Answers1

7

As per @MarkSetchell told me to swap x and y the problem is solved enter image description here

I need to work a little bit in the subplot orientation but look pretty nice solution

PS: Reworked

import matplotlib
matplotlib.use("Agg")
import numpy as np
import matplotlib.pyplot as plt
from scipy import ndimage
from skimage.measure import profile_line
import os
import argparse
import string  
from PIL import Image


plt.rcParams['font.size']=6
plt.rcParams['font.family'] = 'sans-serif'


ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required=True, help="Path to the image")
args = vars(ap.parse_args())
imagen = Image.open(args["image"]) 
imagename=args["image"]  

img = np.array(imagen)

start=(35,0)
end=(35,1300)
profile = profile_line(img,start,end, linewidth=2)


fig, ax = plt.subplots(2,1)
major_ticks = np.arange(0,1350,50)
fig.subplots_adjust(hspace=0,wspace=0)



ax[1].imshow(imagen, cmap=plt.cm.gist_earth, interpolation='gaussian',origin='lower',alpha=1)
ax[1].plot([start[1],end[1]],[start[0],end[0]],'r-',lw=2)
ax[1].set_xticks(major_ticks)
ax[1].grid(color="black", linewidth=0.2)
ax[1].grid(True)

ax[0].plot(profile)
ax[0].set_title('data points = '+str(profile.shape[0])+'')
ax[0].set_xticks(major_ticks)
ax[0].grid(color="black", linewidth=0.2)
ax[0].grid(True)

enter image description here

omaqIX
  • 145
  • 11