LintCode Reserve Integer 翻转整数

Reverse digits of an integer. Returns 0 when the reversed integer overflows (signed 32-bit integer).

Example

Given x = 123, return 321

Given x = -123, return -321

将一个整数中的数字进行翻转,当翻转后的整数溢出时,返回 0 (标记为 32 位整数)。

样例

给定 x = 123,返回 321

给定 x = -123,返回 -321

<pre name="code" class="java">public class Solution {
    /**
     * @param n the integer to be reversed
     * @return the reversed integer
     */
    public int reverseInteger(int n) {
        long m = new Integer(0).longValue();
        while (n != 0) {
            m = m * 10 + n % 10;
            n = n / 10;
        }
        if (m > Integer.MAX_VALUE) {return 0; }
        else {return new Long(m).intValue(); }
    }
}


 

``` import torch from torch_radon import RadonFanbeam, Radon import numpy as np import argparse from pathlib import Path from .helper import load_tiff_stack_with_metadata, save_to_tiff_stack def para_prepare_parallel(index): parser = argparse.ArgumentParser() parser.add_argument('--path_proj', type=str, default='/root/autodl-tmp/DDDM/fan_projections.tif', help='Local path of fan beam projection data.') #Reserve a tif file to quickly pass parameters parser.add_argument('--image_size', type=int, default=736, help='Size of reconstructed image.') # in line with detector number parser.add_argument('--voxel_size', type=float, default=0.7, help='In-slice voxel size [mm].') parser.add_argument('--fbp_filter', type=str, default='hann', nargs='?',choices=['ram-lak', 'shepp-logan', 'cosine', 'hamming', 'hann'], help='Filter used for FBP.') args = parser.parse_args() _, metadata = load_tiff_stack_with_metadata(Path(args.path_proj)) vox_scaling = 1 / args.voxel_size bias = 0 # To control the rotation angle of CT image angles = np.array(metadata['angles'])[:metadata['rotview']+bias] + (np.pi / 2) if index == 1: angles = angles[np.arange(0+bias, 1152+bias, index)] elif index == 16.5: #.5 means half-scan, integer part means the down-sample factor. angles = (angles[np.arange(0+bias, 1152+bias, 16)])[np.arange(0,36,1)] elif index == 8.5: angles = (angles[np.arange(0+bias, 1152+bias, 8)])[np.arange(0,72,1)] elif index == 4.5: angles = (angles[np.arange(0+bias, 1152+bias, 4)])[np.arange(0,144,1)] elif index == 2.5: angles = (angles[np.arange(0+bias, 1152+bias, 2)])[np.arange(0,288,1)] # radon = RadonFanbeam(args.image_size, # angles, # source_distance=vox_scaling * metadata['dso'], # det_distance=vox_scaling * metadata['ddo'], # det_count=736, # det_spacing=vox_scaling * metadata['du'], # clip_to_circle=False) radon = Radon(736, angles=angles, clip_to_circle=True) return radon def run_reco(projections, radon): # projections = projections[:,range_clip,:] # If FBP results are weired, try uncomment this line. if(len(projections.shape) == 4): sino = projections elif (len(projections.shape) == 3): sino = torch.flip(projections, dims=[2]) elif (len(projections.shape) == 2): sino = torch.flip(projections, dims=[1]) filtered_sinogram = radon.filter_sinogram(sino, filter_name='hann') fbp = 100 * radon.backprojection(filtered_sinogram) return fbp```分析代码内容
最新发布
03-26
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值