Skip to content

Commit aa086ad

Browse files
author
Ricardo Dodds
committed
doc: add api endpoint to readme
1 parent 8a88e80 commit aa086ad

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

README.md

+60
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,66 @@ If you don't have access to GPU or appropriate hardware and don't want to instal
216216

217217
![DeepLIIF Website Demo](images/deepliif-website-demo.gif)
218218

219+
DeepLIIF can also be accessed programmatically through an endpoint by posting a multipart-encoded request
220+
containing the original image file:
221+
222+
```
223+
POST /api/infer
224+
225+
Parameters
226+
227+
img (required)
228+
file: image to run the models on
229+
230+
resolution
231+
string: resolution used to scan the slide (10x, 20x, 40x), defaults to 20x
232+
233+
pil
234+
boolean: if true, use PIL.Image.open() to laod the image, instead of python-bioformats
235+
236+
slim
237+
boolean: if true, return only the segmentation result image
238+
```
239+
240+
For example, in Python:
241+
242+
```python
243+
import os
244+
import json
245+
import base64
246+
from io import BytesIO
247+
248+
import requests
249+
from PIL import Image
250+
251+
# Use the sample images from the main DeepLIIF repo
252+
images_dir = './Sample_Large_Tissues'
253+
filename = 'ROI_1.png'
254+
255+
res = requests.post(
256+
url='https://deepliif.org/api/infer',
257+
files={
258+
'img': open(f'{images_dir}/{filename}', 'rb')
259+
},
260+
# optional param that can be 10x, 20x (default) or 40x
261+
params={
262+
'resolution': '20x'
263+
}
264+
)
265+
266+
data = res.json()
267+
268+
def b64_to_pil(b):
269+
return Image.open(BytesIO(base64.b64decode(b.encode())))
270+
271+
for name, img in data['images'].items():
272+
output_filepath = f'{images_dir}/{os.path.splitext(filename)[0]}_{name}.png'
273+
with open(output_filepath, 'wb') as f:
274+
b64_to_pil(img).save(f, format='PNG')
275+
276+
print(json.dumps(data['scoring'], indent=2))
277+
```
278+
219279
## Synthetic Data Generation
220280
The first version of DeepLIIF model suffered from its inability to separate IHC positive cells in some large clusters,
221281
resulting from the absence of clustered positive cells in our training data. To infuse more information about the

0 commit comments

Comments
 (0)