jcupitt / vipsdisp

Tiny libvips / gtk+4 image viewer
MIT License
130 stars 10 forks source link

How to use vipsdisp for pyvips python #2

Closed shivamchaubey closed 2 years ago

shivamchaubey commented 6 years ago

Hello @jcupitt, I am using pyvips for my project and it's helping me lot in mosaicing image. Thanks for such a wonderful tool. :) Now I want to display my final image using vipsdisp. I am figuring out how i can use this with my pyvips code. I haven't found any documentation to integrate it with pyvips, can you suggest how to integrate this.

This code is just for reference:

import os 
from os.path import isfile, join
import re
import sys
import pyvips
import numpy as np
from tqdm import tqdm

images = []
mypath="/media/lab/Seagate Backup Plus Drive/Hinduja Scans/CASE6/CASE6_2_focused/"
onlyfiles = [ f for f in os.listdir(mypath) if isfile(join(mypath,f)) ]
images = np.empty(len(onlyfiles), dtype=object)
onlyfiles.sort(key=lambda var:[int(x) if x.isdigit() else x for x in re.findall(r'[^0-9]|[0-9]+', var)])

row=10
column=50
x_overlap=480-92
y_overlap=640-164
blend_size=100
n=0
y=0

for r in tqdm(range(row)):
    x=0

    for c in range(column-1):
        x+=x_overlap
        if c==0:
            tile1 = pyvips.Image.new_from_file(join(mypath,onlyfiles[n]), access="sequential")
        tile2 = pyvips.Image.new_from_file(join(mypath,onlyfiles[n+1]), access="sequential")                                            
        tile1 = tile2.merge(tile1, 'horizontal', -x, 0, mblend =blend_size)    
        n+=1
    if r==0:
        column_stitch=tile1
    if r>0:
        column_stitch = tile1.merge(column_stitch, 'vertical', 0, -y, mblend =False)    
    y+=y_overlap        
column_stitch.write_to_file('test.tiff',bigtiff=True)

To run this set :

I want to dispaly column_stitch, final mosaiced image using vipsdisp.

jcupitt commented 6 years ago

It would be awkward to mix python and C like that. I would reimplement the display part in pygtk or similar, or reimplement your mosaicing in C or C++.

Have a look at vipsdisp-tiny -- it shows how to use gtk to display the output of a libvips pipeline. It's only a few hundred lines of C and easy to read.

https://github.com/jcupitt/vipsdisp-tiny