;+ ; ; NAME : IMAGE_COMPRESS ; ; PURPOSE : ; Compress an image into a byte image ; CALLING SEQUENCE : ; result = IMAGE_COMPRESS(image, direction, par, $ ; minbyte=minbyte, maxbyte=maxbyte, $ ; bytscl=bytscl, quasilog=quasilogm sqrt=sqrt ; INPUTS : ; IMAGE input image ; ; DIRECTION if equal to 1, compression ; if equal to -1, decompression ; PAR compression parameters ; (in the case of decompression) ; OUTPUTS: ; PAR (in the case of compression) ; KEYWORDS : ; MINBYTE The minimum value for ; the compressed byte image (default=0) ; MAXBYTE The maximum value for ; the compressed byte image (default=255) ; BYTSCl if set, byte scaling method is used. ; par(0) = maximum value of uncompressed image ; par(1) = minimum value of uncompressed image ; QUASILOG if set, quasi log compression is used. ; par(0) = maximum value of uncompressed image ; par(1) = minimum value of uncompressed image ; ; MODIFICATION HISTORY ; March 1997, Jongchul Chae ;- function image_compress, image, direction, $ par, minbyte=minbyte, maxbyte=maxbyte, $ bytscl=bytscl, $ quasilog=quasilog, sqrt=sqrt if n_elements(minbyte) eq 0 then minbyte=0 else minbyte=byte(minbyte) if n_elements(maxbyte) eq 0 then maxbyte=255 $ else maxbyte=byte(maxbyte) if n_elements(direction) eq 0 then direction=1 if keyword_set(quasilog) then case direction of 1 : begin max=max(image, min=min) par=[max, min] scal=(maxbyte-minbyte)/alog((max-min)>2.) x=indgen(maxbyte-minbyte)+1 res=abs(scal*alog(x)-x) turn_off = max(x(where(res le 1.)>0)) tmp=image-min value=round(minbyte+tmp*(tmp le turn_off-minbyte) $ +scal*alog(tmp>1.)*(tmp gt turn_off-minbyte)) value=value>minbyte2.) x=indgen(maxbyte-minbyte)+1 res=abs(scal*alog(x)-x) turn_off = max(x(where(res le 1.)>0)) tmp=image-minbyte value = min + tmp*(tmp le (turn_off-minbyte)) $ + exp(tmp/scal)*(tmp gt (turn_off-minbyte)) end endcase if keyword_set(bytscl) then case direction of 1 : begin max=max(image, min=min) if max eq min then max=max+1 par=[max, min] value = round(minbyte $ +float(maxbyte-minbyte)*(image-min)/((max-min)) ) value=value>minbyteminbyte